篡改汇总模式的结果
有了上一节“关于汇总模式下的行”的知识,我们就可以轻松地“篡改”汇总模式的统计结果。
示例一
例如希望汇总模式的统计结果中,金额以“万元”为单位显示:
'首先要生成汇总模式
示例二
假定要生成下图所示的汇总模式,显然常规的方法是不可能的:
有了上一节的知识,我们可以用如下的代码实现,望大家仔细体会:
Dim
t As
Table = Tables("表A")
Dim
g As
Subtotalgroup
t.SubtotalGroups.Clear()
g
= New
Subtotalgroup
g.GroupOn
= "分组1"
g.TotalOn
= "金额"
t.SubtotalGroups.Add(g)
Dim
groups As
List(of
String) = DataTables("表A").GetValues("分组2")
For
Each grp
As String
In groups
g = New
Subtotalgroup
g.GroupOn
= "*"
g.Caption
= "总计"
t.SubtotalGroups.Add(g)
Next
t.Subtotal()
Dim
cnt As
Integer = Tables("表A").Rows.Count(True)
- groups.count
For
Each group
As String
In groups
Tables("表A").Rows(cnt,True)("分组2")
= group
Tables("表A").Rows(cnt,True)("金额")
= Tables("表A").Compute("Sum(金额)","分组2
= '"
&group &
"'")
cnt
= cnt +1
Next