Vars("w")=""
Dim r As DataRow = args(0)
Dim drr As DataRow= DataTables("系统设置").sqlFind("图章存储位置<>''")
Dim bglx As String= r("报告类型")
Dim Proc As New Process '打开PDF文件
Dim b As WinForm.Label = Forms("首页").Controls("Label1")
b.Text="正在打印"
Dim cmd As new SQLCommand
cmd.C
cmd.CommandText="s elect 签名 from 用户表 where username ='"& r("审核") &"'"
Dim shqm As String= cmd.ExecuteScalar
cmd.CommandText="s elect 签名 from 用户表 where username ='"& r("批准") &"'"
Dim pzqm As String= cmd.ExecuteScalar
'cmd.CommandText="s elect 签名 from 用户表 where username ='"& r("制单") &"'"
Dim zjy As String= r("质检员")
'Dim r As Row = Tables("质检报告主表").Current
If r("单据状态")<>"" Then
'If r("报告类型")="包装油出厂检验报告" Then
Dim Book As New XLS.Book(drr("图章存储位置") & "Attachments\"& r("报告类型") &".xlsx")
Dim fl As String = ProjectPath & "Reports\PDF"& format(now(),"yyMMdd")& Rand.Next(1000) &".xlsx"
If r("质检员")="" Then
MessageBox.Show("尚未制定质检员,请选择")
Return 0
End If
book.AddDataTable("质检报告主表","pk","S elect * from 质检报告主表 where 编号= '"& r("编号")&"'") '添加父表
book.AddDataTable("质检报告附表","pk","S elect * from 质检报告附表 where 编号= '"& r("编号") &"'") '添加子表
book.AddDataTable("成品有出厂检验","pk","S elect * from 成品有出厂检验 where 编号= '"& r("编号") &"'And 产品名称='"& Vars("pinming") &"' and 规格='"& Vars("guige") &"'") '添加子表
book.AddRelation("质检报告主表","编号","质检报告附表","编号") '建立关联
book.AddRelation("质检报告主表","编号","成品有出厂检验","编号") '建立关联
Dim Sheet As XLS.Sheet = Book.Sheets(0)
'
For i1 As Integer=0 To 25
For j As Integer=0 To 25
If sheet(i1,j).Value="检验员:" Then
sheet(i1,j+1).Value=New XLS.Picture(GetImage(zjy))
'sheet(i1,j+3).Value=New XLS.Picture(GetImage(shqm))
sheet(i1,j+5).Value=New XLS.Picture(GetImage(shqm))
Exit For
End If
If sheet(i1,j).Value="结论" Then
Sheet(i1, j+3).Value = New XLS.Picture(GetImage(drr("质检公章")))
'Sheet(0, 3).Value = New XLS.Picture(GetImage(drr("质检公章")))
Exit For
End If
Next
Next
'Sheet(Sheet.Rows.Count-7, 4).Value = New XLS.Picture(GetImage(drr("质检公章")))
'Sheet(0, 2).Value = New XLS.Picture(GetImage(drr("质检公章")))
Book.Build() '
''开始打印报告
book.Save(fl)
'cmd.CommandText= "u pdate 身份证信息 set 报告编号='"& vars("报告编号") &"' ,打印时间= '"& Date.Now &"' where 身份证号码='"& vars("haoma") &"' And 读取日期= '"& Date.Today &"' "
'Dim dss As DataRow= DataTables("身份证信息").SQLFind("身份证号码='"& Vars("号码") &"' And 读取日期= '"& Date.Today &"' ")
'If dss IsNot Nothing Then
'dss("报告编号")= r("编号")
'dss("打印时间")= Date.Now
'dss.Save
'End If
'
'cmd.ExecuteNonQuery
'MessageBox.Show(cmd.CommandText)
Dim App As New MSExcel.Application
Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open(fl)
Dim Ws As MSExcel.WorkSheet
If bglx.Contains("包装") Then
ws = Wb.WorkSheets("包装油出厂质检报告")
Else
ws= Wb.WorkSheets("油脂发货检验报告")
End If
With Ws.PageSetup
.PrintArea = "A1:H10" '打印工作表的指定区域
.PrintArea = Ws.UsedRange.Address '打印工作表的使用区域
'.PrintTitleColumns = Ws.Columns("A:H").Address '打印列标题(在每一页的左边重复出现)
.PrintTitleRows = Ws.Rows(1).Address '打印行标题(在每一页的顶部重复出现)
'设置页面
.PaperSize = MSExcel.XlPaperSize.xlPaperA4 '纸张大小
.LeftMargin = 30 '页面左边距
.RightMargin = 30'页面右边距
.TopMargin = 50 '页面顶部边距
.BottomMargin = 50 '页面底部边距
.HeaderMargin = 40 '页面顶端到页眉的距离
.FooterMargin = 40 '页脚到页面底端的距离
.CenterHorizontally = True '页面水平居中
.CenterVertically = True '页面垂直居中
''设置页眉
.LeftHeader = "打印日期: &D" '左页眉,&D表示日期
.CenterHeader = "&""隶书,常规""&20 " '中页眉,并将字体设置为隶书和20号字大小
.RightHeader = "打印: " & vars("姓名") & Vars("号码") 'App.UserName '右页眉
''设置页脚
'' .LeftFooter = "文件: &F &A" '左页脚,&F表示文件名,&A表示工作表名
.CenterFooter = "" '中页脚为空
.RightFooter = "第 &P 页 共 &N 页" '右页脚
''打印模式
.Orientation = MSExcel.xlPageOrientation.xlPortrait '纵向打印
''.Orientation = MSExcel.xlPageOrientation.xlLandscape '横向打印
'' .PrintHeadings = True'打印行号和列标
'' .PrintGridlines = True '打印网格线
''缩放打印
.Zoom = False '以下设置将缩印在一页内
.FitToPagesWide = 1 '按照1页的宽度打印
.FitToPagesTall = 1 '按照1页的高度打印
End With
App.Visible = False
Ws.Printout
App.Quit
'wb.Save()
'MessageBox.Show("1")
'Wb.close
Dim ps1 As System.Diagnostics.Process() = System.Diagnostics.Process.GetProcessesByName("excel")
For Each p As System.Diagnostics.Process In ps1
p.kill
Next
Dim ps11 As System.Diagnostics.Process() = System.Diagnostics.Process.GetProcessesByName("wps")
For Each p As System.Diagnostics.Process In ps11
p.kill
Next
Else
MessageBox.Show("请先审核单据在生成报告")
Return 0
'End If
使用上面的代码打印,遇到以下问题
如果 Dim fl As String = ProjectPath & "Reports\PDF"& format(now(),"yyMMdd")& Rand.Next(1000) &".xlsx" 定义成
Dim fl As String = ProjectPath & "Reports\PDF"& format(now(),"yyMMdd")& Rand.Next(1000) &".xls"
在执行时 出现以下报错
无法使用本格式保存该工作簿,至少一个表单包含太多的列
使用Dim fl As String = ProjectPath & "Reports\PDF"& format(now(),"yyMMdd")& Rand.Next(1000) &".xlsx"
打印100多张纸,第一张如下图,后面都是空白
End If
此主题相关图片如下:微信图片_20200706160346.jpg