以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]对数据表进行计录数交叉统计时,不显示横向汇总  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=95716)

--  作者:jyh7081
--  发布时间:2017/2/3 12:27:00
--  [求助]对数据表进行计录数交叉统计时,不显示横向汇总
数据表的单元格都是字符型数据,对他们进行交叉统计时,选中自动汇总模式时,不显示横向汇总。
如果对生成的统计表再进行二次汇总,代码怎么写?

统计代码:
Dim g As New CrossTableBuilder("统计表1", DataTables("表A"))
g.HGroups.AddDef("第一列")
g.HGroups.AddDef("第二列")
g.VGroups.AddDef("第四列")
g.Totals.AddDef("第五列", AggregateEnum.Count, "第五列", True)
g.Subtotal = True
g.Build()
MainTable = Tables("统计表1")

附件:
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:交叉统计后汇总.table



--  作者:有点色
--  发布时间:2017/2/3 14:00:00
--  

要单独写代码

 

Dim dtb As New DataTableBuilder("统计")
dtb.AddDef("第一列", Gettype(String), 16)
dtb.AddDef("第二列", Gettype(String), 16)
Dim prds As List(of String) = DataTables("表A").GetValues("第四列", "第四列 is not null")
Dim str As String = ""
Dim cs As String = ""
For Each prd As String In prds
    dtb.AddDef(prd, Gettype(Double))
    str &= "isnull(" & prd & ",0)+"
    cs &= prd & ","
Next
cs &= "合计"
dtb.AddDef("合计", Gettype(Double), str.trim("+"))
dtb.Build()
For Each cus As String() In DataTables("表A").GetValues("第一列|第二列")
    Dim dr As DataRow = DataTables("统计").AddNew()
    dr("第一列") = cus(0)
    dr("第二列") = cus(1)
    For Each prd As String In prds
        dr(prd) = DataTables("表A").Compute("count(第一列)", "第一列 = \'" & cus(0) & "\' And 第二列 = \'" & cus(1) & "\' and 第四列 = \'" & prd & "\'")
    Next
Next

Dim t As Table = Tables("统计")
Dim g As Subtotalgroup
t.SubtotalGroups.Clear()
t.GroupAboveData = False
t.TreeVisible = False
t.SpillNode = True

g = New Subtotalgroup
g.Aggregate = AggregateEnum.Sum
g.GroupOn = "第一列"
g.TotalOn = cs
g.Caption = "{0} 小计"
t.SubtotalGroups.Add(g)

g = New Subtotalgroup
g.Aggregate = AggregateEnum.Sum
g.GroupOn = "*"
g.TotalOn = cs
g.Caption = "总计"
t.SubtotalGroups.Add(g)

t.Subtotal()

MainTable = t