Dim d As Date = Date.Today
Dim y As Integer = d.Year
Dim m As Integer = d.Month
Dim bh As String = Format(d,"yyyyMM")
Dim ckdh As WinForm.TextBox =e.Form.Controls("出库单号")
Dim rq As WinForm.DateTimePicker = e.Form.Controls("DateTimePicker1")
Dim kg As WinForm.TextBox = e.Form.Controls("制单")
Dim Book As New XLS.Book(ProjectPath & "相关文件\mb2.xls") '打开模板
Dim fl As String = ProjectPath & "Reports\mb2.xls"
Dim Sheet As XLS.Sheet = Book.Sheets(0)
Sheet(1,2).Value = " "& rq.text &""
Sheet(1,9).Value = " "& ckdh.text &""
Sheet(5,2).Value = " "& kg.text &""
Sheet(3,10).Value = "<出库单号 = '"& ckdh.text &"'>" '写入打印条件
Book.Build() '生成报表
Book.Save(fl)
Dim App As New MSExcel.Application
Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open(fl)
Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
With Ws.PageSetup
.PrintArea = Ws.UsedRange.Address '打印工作表的使用区域
.LeftMargin = 20 '页面左边距
.RightMargin = 20 '页面右边距
.TopMargin = 20 '页面顶部边距
.BottomMargin = 20 '页面底部边距
.CenterHorizontally = True '页面水平居中
.Orientation = MSExcel.xlPageOrientation.xlPortrait '纵向打印
End With
App.Visible = True
Ws.PrintPreview
Wb.Save
Wb.SaveAs("E:\网络版\单据\出库\"& bh &"\CK-"& ckdh.text &".xls")
App.Quit