参考代码,思路是,生成各个的excel报表以后,合并到一个总报表里去。
Dim nams As List(Of String)
nams = DataTables("进度").GetValues("模号")
Dim App As New MSExcel.Application
Dim bname As String = ProjectPath & "开单\总报表.xls"
Dim Wb As MSExcel.WorkBook = App.WorkBooks.Add
Wb.WorkSheets(3).delete
Wb.WorkSheets(2).delete
Dim ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
For Each nam As String In nams
If nam <> "" Then '----姓名不是空
Dim Book As New XLS.Book ( ProjectPath & "工作集群\test.xls" )
Dim sheet As XLS.Sheet = Book.Sheets(0)
Tables("进度").filter = "模号 = '" & nam & "'"
Book.Build()
Dim fl As String = ProjectPath & "开单\" & nam & ".xls"
Book.Save(fl) '保存工作簿
Dim Wb_temp As MSExcel.WorkBook = App.WorkBooks.Open(fl)
Dim Ws_temp As MSExcel.WorkSheet = wb_temp.WorkSheets(1)
Ws_temp.name = nam
Ws_temp.Copy(System.Reflection.Missing.Value, ws)
wb_temp.close(False, System.Reflection.Missing.Value, System.Reflection.Missing.Value)
End If
Next
ws.delete
Wb.saveas(bname)
App.Quit
Dim Proc As New Process '打开工作簿
Proc.File = bname
Proc.Start()