可以用一个按钮实现一次性对BOOK的多个SHEET生成表.有一个注意事项,模板中的sheet个数决定了后来可以容纳数据表的个数.
Dim dt As Table = Tables("订单")
Dim Book As New XLS.Book(ProjectPath & "Attatchments\订单.xls") '定义一个Excel工作簿,BOOK是空模板
Book.Save("c:\test1.xls")
Dim Book1 As New XLS.Book("c:\test1.xls") 'Book1即test1.xls是即将生成数据的临时Excel文件
Dim Sheet1 As XLS.Sheet = Book1.Sheets(0) '引用工作簿的第一个工作表
For r As Integer = 0 To dt.Rows.Count - 1 '填入数据
For c As Integer = 0 To dt.Cols.Count -1
Sheet1(r +1, c).Value = dt.rows(r)(c)
Next
Next
Dim Sheet2 As XLS.Sheet = Book1.Sheets(1) '引用工作簿的第二个工作表
For r As Integer = 0 To dt.Rows.Count - 1 '填入数据
For c As Integer = 0 To dt.Cols.Count -1
Sheet2(r +1, c).Value = dt.rows(r)(c)
Next
Next
'打开工作簿
Book1.Save("c:\test1.xls")
Dim Proc As New Process
Proc.File = "c:\test1.xls"
Proc.Start()