--
Dim dt As DataTable = DataTables("订单")
Dim Book As New XLS.Book \'定义一个Excel工作簿
Book.Sheets.RemoveAt(0)
Dim Sheet As XLS.Sheet
For Each s As String In dt.GetValues("客户")
For Each m As String In dt.GetValues("产品","客户 = \'" & s & "\'")
Sheet = Book.Sheets.Add(s & m) \'新建一个sheet
For c As Integer = 0 To dt.DataCols.Count -1 \'添加列标题
Sheet(0, c).Value = dt.DataCols(c).Name
Next
Dim drs As List(Of DataRow) = dt.Select("产品 = \'" & m & "\'")
For r As Integer = 0 To drs.Count - 1
For c As Integer = 0 To dt.DataCols.Count -1
Sheet(r +1, c).Value = drs(r)(dt.dataCols(c).Name)
Next
Next
Next
Next
Dim dlg As New SaveFileDialog \'定义一个新的SaveFileDialog
dlg.Filter= "Excel文件|*.xls" \'设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then
Book.Save(dlg.FileName)
Dim Proc As New Process
Proc.File = dlg.FileName
Proc.Start()
End If
老师,这次是想按客户下的每个产品分别导出,按以上代码试了一下,始终有错误提示,请老师指导,修改一下