不要自己fill自己,增加一个窗口表
Dim g As New GroupTableBuilder("统计表1", DataTables("表A"))
g.Groups.AddDef("部门")
g.Totals.AddDef("课题编码", AggregateEnum.Count, "数量")
g.Decimals = 0
g.FromServer = True
g.Build()
'MainTable = Tables("统计表24")
Dim dt As Date = Date.Today
Dim Vals As List(of String)
Vals = DataTables("统计表1").GetValues("部门") '从统计表中获得所有部门的集合
Dim cmd As new sqlcommand
Dim t As Table = e.Form.Controls("Table1").Table
For i As Integer = 0 To Vals.Count - 1
t.Fill("select * from {表A} where 部门 = '" & Vals(i) & "'",False)
t.saveExcel("d:\reports\表A" & dt & ".xls", Vals(i))
Next
MessageBox.Show("数据已导出,在 D:\Reports 文件夹中查看~!","恭喜",MessageBoxButtons.OK,MessageBoxIcon.Information)