如果不考虑合并单元格,这种方法也可以,原理就是添加一个sheet,然后把之前的sheet的内容全部复制到新的sheet里
Dim Products As List(Of String)
Products = DataTables("出库").SQLGetValues("出库用途")
Dim Book As New XLS.Book(ProjectPath & "Attachments\出库单.xls") '打开模板
Dim fl As String = ProjectPath & "Reports\出库单.xls"
Dim Sheet As XLS.Sheet = Book.Sheets(0)
Dim Sheet2 As XLS.Sheet
If Products.Count > 0 Then Sheet(1,7).Value = "<出库用途 ='" & Products(0) & "'>"
For i As Integer = 1 To Products.Count - 1
Book.Sheets.Add(Products(i))
Sheet2 = Book.Sheets(Products(i))
For r As Integer = 0 To Sheet.Rows.Count - 1 '填入数据
Sheet2.Rows(r).Height = Sheet.Rows(r).Height
For c As Integer = 0 To Sheet.Cols.Count -1
Sheet2.Cols(c).Width = Sheet.Cols(c).Width
Sheet2(r, c).Value = Sheet(r, c).Value
Sheet2(r, c).Style = Sheet(r, c).Style
Next
Next
Sheet2(1,7).Value = "<出库用途 ='" & Products(i) & "'>" '写入打印条件='"& Product & "'
Next
Book.Build() '生成报表
Book.Save(fl)
Dim Proc As New Process
Proc.File = fl
Proc.Start()