这样就自动了:
If DataTables.Contains("产品出货统计") '如果存在产品出货统计表则删除
DataTables.Delete("产品出货统计")
End If
Dim b As New SQLCrossTableBuilder("产品出货统计","出库明细")
b.AddTable("出库明细","出库单号","出库单","出库单号") '添加统计表
b.HGroups.AddDef("产品编码") '添加水平分组列
b.HGroups.AddDef("{出库明细}.品名") '添加水平分组列
b.HGroups.AddDef("{出库明细}.规格") '添加水平分组列
b.VGroups.AddDef("出库日期",DateGroupEnum.Year,"{0}年") '添加日期列用于垂直分组,按年分组
b.VGroups.AddDef("出库日期","{0}月") '添加日期列用于垂直分组,按月分组
b.Totals.AddDef("{出库明细}.数量") '添加数量列用于统计
b.Build '生成统计表
MainTable = Tables("产品出货统计") '打开生成的统计表
Dim t As Table = Tables("产品出货统计")
Dim g As Subtotalgroup
t.SubtotalGroups.Clear()
t.GroupAboveData = False
t.TreeVisible = False
t.SpillNode = True
g = New Subtotalgroup
g.Aggregate = AggregateEnum.Sum
g.GroupOn = "产品编码"
For Each c As col In Tables("产品出货统计").Cols
If c.DataCol.IsNumeric Then
g.TotalOn = g.TotalOn & "," & c.name
End If
Next
g.TotalOn = g.Totalon.trim(",")
g.Caption = "{0} 小计"
t.SubtotalGroups.Add(g)
t.Subtotal() '生成汇总模式