篡改汇总模式的结果

有了上一节“关于汇总模式下的行”的知识,我们就可以轻松地“篡改”汇总模式的统计结果。

示例一

例如希望汇总模式的统计结果中,金额以“万元”为单位显示:

'首先要生成汇总模式
Dim
r As Row
For
i As Integer = 0 To Tables("订单").Rows.Count(True) - 1
    r = Tables("订单").Rows(i,True)
    If
r.IsGroup
        r
("金额") = r("金额") / 10000 & "万元"
   
End
If
Next

示例二

假定要生成下图所示的汇总模式,显然常规的方法是不可能的:

有了上一节的知识,我们可以用如下的代码实现,望大家仔细体会:

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


本页地址:http://www.foxtable.com/webhelp/topics/1911.htm