'对临时进行分组统计
Dim b As New CrossTableBuilder("统计表1",DataTables("财务数据源"))
b.HGroups.AddDef("日期",DateGroupEnum.Year,"年")
b.HGroups.AddDef("日期","月")
b.HGroups.AddDef("字号")
b.HGroups.AddDef("凭证号")
b.HGroups.AddDef("摘要")
b.VGroups.AddDef("二级科目","{0}")
b.Totals.AddDef("借方金额")
b.Build()
Dim a As Table = Tables("统计表1")
Dim g As Subtotalgroup
a.SubtotalGroups.Clear()
Dim s As String = ""
For Each c As Col In a.Cols
If c.Name Like "借方金额_*"
s = s & "," & c.Name
End If
Next
g = New Subtotalgroup
g.GroupOn = "月"
g.TotalOn = s.Trim(",")
g.Caption = "本月发生额"
a.SubtotalGroups.Add(g)
g = New Subtotalgroup
g.GroupOn = "月"
g.Caption = "{0}月"
a.SubtotalGroups.Add(g)
a.Sort = "年,月"
a.Subtotal(True)
Dim r As Row
For i As Integer = 0 To a.Rows.Count(True) - 1
r = a.Rows(i,True)
If r.IsGroup AndAlso r("年") Like "*月" '如果是分组行
Dim f As String = "年 = " & a.Rows(i-2,True)("年") & " And 月 <= " & r("年").trim("月")
r("年") = "本年累计"
For Each c As Col In a.Cols
If c.Name Like "借方金额_*"
r(c.Name) = a.Compute("Sum(" & c.Name & ")",f)
End If
Next
End If
Next
Dim ckb As DataTable = a.DataTable
If ckb.DataCols.Contains("借或贷") = False And ckb.DataCols.Contains("借方合计") = False And ckb.DataCols.Contains("贷方合计") = False Then
ckb.DataCols.add("借或贷", Gettype(String))
ckb.DataCols.add("借方合计", Gettype(Double))
ckb.DataCols.add("贷方合计", Gettype(Double))
End If
ckb.DataCols("借方合计").SetFormat("#,###.##")
ckb.DataCols("贷方合计").SetFormat("#,###.##")
a.SetHeaderRowHeight(45)