以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]如何在TotalOn表达多个Totals.AddDef列名  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=73058)

--  作者:乡里出城
--  发布时间:2015/8/11 16:26:00
--  [求助]如何在TotalOn表达多个Totals.AddDef列名
如:
Dim g1 As New CrossTableBuilder("统计表1", DataTables("订单"))
g1.VGroups.AddDef("雇员")
g1.Totals.AddDef("金额")    \'这个两个代码在新的统计表1中生成很多列,列(以雇员为列标题,根据雇员的数量分别生成对应的金额_1,金额_2,金额_3,金额_4,金额_5,.........生成了很多列)


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

g = New Subtotalgroup
g.Aggregate = AggregateEnum.Sum
g.GroupOn = "产品"
g.TotalOn = "金额_1,金额_2,金额_3,金额_4,金额_5"        \'然后在统计这里,TotalOn = “ 这里是否只能指定列名,如左边,现在能否用一个赋值来代才替,因为不知道会有多金额_1,金额_2,金额_?......不知道会有多少列
g.Caption = "{0} 小计"
t.SubtotalGroups.Add(g)

谢谢
[此贴子已经被作者于2015/8/11 16:27:04编辑过]

--  作者:大红袍
--  发布时间:2015/8/11 16:31:00
--  
Dim str As String = ""
For Each c As Col In Tables("统计表1").cols
    If c.Name Like "*金额*" Then
        str &= c.name & ","
    End If
Next
msgbox(str.trim(","))

--  作者:乡里出城
--  发布时间:2015/8/11 16:39:00
--  
Dim g1 As New CrossTableBuilder("统计表1", DataTables("订单"))
g1.HGroups.AddDef("客户")
g1.HGroups.AddDef("产品")
g1.VGroups.AddDef("雇员")
g1.Totals.AddDef("金额")
g1.VerticalTotal = True
g1.HorizontalTotal = True
g1.OrderByTotal = e.Form.Controls("CheckBox1").Checked
g1.Build()
Tables("统计表1").AutoSizeCols(10)
MainTable = Tables("统计表1")

Forms("返回").OpenTo("统计表1")
Forms("返回").Controls("TextBox1").Value = "提示: 不同客户订购各种产品的数量和金额。"
MainTable.Focus()

\'\'\'
Dim str As String = ""
For Each c As Col In Tables("统计表1").cols
    If c.Name Like "*金额*" Then
        str &= c.name & ","
    End If
Next
  


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

g = New Subtotalgroup
g.Aggregate = AggregateEnum.Sum
g.GroupOn = "产品"
g.TotalOn = str.trim(",")
g.Caption = "{0} 小计"
t.SubtotalGroups.Add(g)



g = New Subtotalgroup
g.Aggregate = AggregateEnum.Sum
g.GroupOn = "*"
g.TotalOn = str.trim(",")

g.Caption = "总计"
t.SubtotalGroups.Add(g)

t.Subtotal()
t.Grid.Tree.Show(1)
t.Grid.Tree.Show(0)
t.Grid.Rows(2).Node.Expanded = True
t.Grid.Rows(3).Node.Expanded = True
t.ResumeRedraw()

以上是原码,大红袍,我把你写的那行代码表述进去
[此贴子已经被作者于2015/8/11 17:14:31编辑过]

--  作者:乡里出城
--  发布时间:2015/8/13 11:39:00
--  
结果合计的最后倒数第二列产品是没有数的
--  作者:大红袍
--  发布时间:2015/8/13 11:50:00
--  

我测试显示正确啊,是不是合计列没有计算?你要加什么都可以啊

 

Dim str As String = ""
For Each c As Col In Tables("统计表1").cols
    If c.Name Like "*金额*" Then
        str &= c.name & ","
    End If
Next 
str &= "合计"