Dim nams As List(Of String) = DataTables("备料明细").GetValues("供货方","订单号 = '" & cr("订单号") & "'")
Dim App As New MSExcel.Application
Dim bname As String = "d:\物料采购\物料采购清单.xlsx"
Dim Wb As MSExcel.WorkBook = App.WorkBooks.Add
Dim ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
For Each nam As String In nams
Dim Book As New XLS.Book ( ProjectPath & "Attachments\物料采购清单.xls" ) '调用模板
Dim sheet As XLS.Sheet = Book.Sheets(0)
Tables("备料明细").filter = "供货方 = '" & nam & "' and 订单号 = '" & cr("订单号") & "'"
Book.Build()
Dim fl As String = "d:\物料采购\" & 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)
Next
ws.delete
Wb.saveas(bname)
App.Quit
Dim Proc As New Process '打开工作簿
Proc.File = bname
Proc.Start()