Foxtable(狐表)用户栏目专家坐堂 → [求助]交叉统计设置


  共有2322人关注过本帖树形打印复制链接

主题:[求助]交叉统计设置

帅哥哟,离线,有人找我吗?
有点色
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:13837 积分:69650 威望:0 精华:0 注册:2016/11/1 14:42:00
  发帖心情 Post By:2016/11/11 18:22:00 [显示全部帖子]

参考代码

 

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("统计")

 


 回到顶部