试试以下代码:
表1
Dim g As New CrossTableBuilder("统计表", DataTables("表B"))
g.HGroups.AddDef("缺陷等级")
g.VGroups.AddDef("月")
g.Totals.AddDef("月", AggregateEnum.Count)
g.HorizontalTotal = True
g.Build()
Tables("统计表").AutoSizeColsMainTable = Tables("统计表")
表2
Dim dtb As New DataTableBuilder("中间表")
dtb.AddDef("缺陷原因", Gettype(String), 32)
dtb.AddDef("月", Gettype(String), 32)
dtb.TableVisible = False
dtb.Build()
For Each dr As DataRow In DataTables("表B").DataRows
For Each s As String In dr("缺陷原因").split(",")
Dim dr1 As DataRow = DataTables("中间表").AddNew
dr1("缺陷原因") = s
dr1("月") = dr("月")
Next
Next
Dim b As New CrossTableBuilder("统计表",DataTables("中间表"))
b.HGroups.AddDef("缺陷原因")
b.VGroups.AddDef("月")
b.Totals.AddDef("月",AggregateEnum.Count)
b.HorizontalTotal = True
b.Build
Tables("统计表").AutoSizeCols
MainTable = Tables("统计表")
表3
Dim dtb As New DataTableBuilder("中间表")
dtb.AddDef("责任人", Gettype(String), 32)
dtb.AddDef("缺陷原因", Gettype(String), 32)
dtb.AddDef("月", Gettype(String), 32)
dtb.TableVisible = False
dtb.Build()
For Each dr As DataRow In DataTables("表B").DataRows
For Each s As String In dr("缺陷原因").split(",")
Dim dr1 As DataRow = DataTables("中间表").AddNew
dr1("责任人") = dr("责任人")
dr1("缺陷原因") = s
dr1("月") = dr("月")
Next
Next
Dim b As New CrossTableBuilder("统计表",DataTables("中间表"))
b.HGroups.AddDef("责任人")
b.HGroups.AddDef("缺陷原因")
b.VGroups.AddDef("月")
b.Totals.AddDef("月",AggregateEnum.Count)
b.HorizontalTotal = True
b.Build
Tables("统计表").AutoSizeCols
MainTable = Tables("统计表")