参考代码
Dim dt As DataTable = DataTables("表A")
Dim dtb As New DataTableBuilder("统计")
dtb.AddDef("年", Gettype(String), 16)
dtb.AddDef("周", Gettype(String), 16)
dtb.AddDef("说明", Gettype(String), 16)
Dim prds As List(of String) = dt.GetValues("组别")
For Each prd As String In prds
dtb.AddDef(prd, Gettype(Double))
Next
dtb.AddDef("合计", Gettype(Double))
dtb.AddDef("调整方案", Gettype(Double))
dtb.Build()
Dim ary_shuoming() As String = {"人数", "产能", "排单量"}
For Each ary() As String In dt.GetValues("年|周")
For Each shuoming As String In ary_shuoming
Dim dr As DataRow = DataTables("统计").AddNew()
dr("年") = ary(0)
dr("周") = ary(1)
dr("说明") = shuoming
Dim sum As Double = 0
For Each prd As String In prds
dr(prd) = dt.Compute("sum(" & shuoming & ")", "年 = '" & ary(0) & "' and 周 = '" & ary(1) & "' and 组别 = '" & prd & "'")
sum += dr(prd)
Next
dr("合计") = sum
Next
Next
With Tables("统计")
.MergeMode = MergeModeEnum.Standard
.MergeCols.Clear()
.MergeCols.Add("年")
.MergeCols.Add("周")
.MergeSort = "年,周"
.AllowMerge = True
End With
MainTable= Tables("统计")