以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- [求助] 筛选后的数据分组统计,怎么搞 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=70038) |
||
-- 作者:wangyinming -- 发布时间:2015/6/15 9:31:00 -- [求助] 筛选后的数据分组统计,怎么搞 我想筛选后的数据分组统计,但是不行,出来总是所有数据的,请老师指教 [此贴子已经被作者于2015/6/15 11:16:08编辑过]
|
||
-- 作者:Bin -- 发布时间:2015/6/15 9:37:00 -- 先筛选,再汇总即可 |
||
-- 作者:wangyinming -- 发布时间:2015/6/15 9:53:00 -- 我是这样的结构,现①筛选,②再汇总。试了一下1天的数据,导出来还是全月的。不行啊,是不是结构不行,还是代码有问题啊 ①的代码:Dim gx As WinForm.ComboBox = e.Form.Controls("工序") Dim jt As WinForm.combobox = e.Form.Controls("机台") Dim xh As WinForm.combobox = e.Form.Controls("型号") Dim gh As WinForm.combobox = e.Form.Controls("工号") Dim glhm As WinForm.combobox = e.Form.Controls("管理号码") Dim filter As String = "1=1" If gx.Text > "" Then filter &= " and 工程 = \'" & gx.Text & "\'" End If If jt.Text > "" Then filter &= " and 机台号码 = \'" & jt.Text & "\'" End If If xh.Text > "" Then filter &= " and 型号 = \'" & xh.Text & "\'" End If If gh.Text > "" Then filter &= " and 工号 = \'" & gh.Text & "\'" End If If glhm.Text > "" Then filter &= " and 管理号码 = \'" & glhm.Text & "\'" End If With e.Form.Controls("开始时间") If .Value IsNot Nothing Then If Filter >"" Then Filter = Filter & " And " End If Filter = Filter & "作业日期>= #" & .Value & "#" End If End With With e.Form.Controls("结束时间") If .Value IsNot Nothing Then If Filter >"" Then Filter = Filter & " And " End If Filter = Filter & "作业日期<= #" & .Value & "#" End If End With Tables("加硫").Filter = filter ②的代码:Dim g As New GroupTableBuilder("统计表1", DataTables("加硫")) g.Groups.AddDef("型号") g.Totals.AddDef("生产数") g.Totals.AddDef("实际成型回数") g.Totals.AddDef("标准成型回数") g.VerticalTotal = True g.Build() Dim t As Table = Tables("统计表1") Dim dc = t.DataTable.DataCols.Add("缺损率", Gettype(Double), "(实际成型回数-标准成型回数)/标准成型回数") dc.SetFormat("0.00%") MainTable = Tables("统计表1") If MessageBox.Show("确定要生成所选数据的模具缺损率吗?","确认",MessageBoxButtons.YesNo,MessageBoxIcon.Question) = DialogResult.Yes Then Dim dlg As New SaveFileDialog \'定义一个新的SaveFileDialog dlg.Filter= "Excel文件|*.xls" \'设置筛选器 If dlg.ShowDialog = DialogResult.Ok Then \'如果用户单击了确定按钮 Tables("统计表1").SaveExcel(dlg.FileName, "模具缺损率") \'保存文件 End If messagebox.show("生成成功!","确认") DataTables.Unload("统计表1") Else e.Form.controls("Button2").Select End If |
||
-- 作者:大红袍 -- 发布时间:2015/6/15 10:05:00 -- Tables("加硫").Filter = filter
这句代码,是无效的,你要这样写,如
g.Filter = Filter |
||
-- 作者:wangyinming -- 发布时间:2015/6/15 10:28:00 -- 不会写,是不是要定义引用变量的啊,怎么定义啊,事例有吗?不会写 [此贴子已经被作者于2015/6/15 10:30:02编辑过]
|
||
-- 作者:yan2006l -- 发布时间:2015/6/15 10:28:00 -- 方案一:有可能的你的table是窗口的副本,所以你表名改成窗口那种名字试验一下 方案二:你直接对datetable分组统计,然后在分组统计里面补上条件,分组统计可以加条件的。 |
||
-- 作者:wangyinming -- 发布时间:2015/6/15 10:34:00 --
|
||
-- 作者:大红袍 -- 发布时间:2015/6/15 10:35:00 -- Dim g As New GroupTableBuilder("统计表1", DataTables("加硫")) g.Groups.AddDef("型号")
g.Totals.AddDef("生产数")
g.Totals.AddDef("实际成型回数")
g.Totals.AddDef("标准成型回数")
g.VerticalTotal = True
g.Filter = Filter g.Build()
|
||
-- 作者:wangyinming -- 发布时间:2015/6/15 10:40:00 -- 老师,我是2个代码分开好呢,还是写一起好呢 分开写的话 g.Filter = Filter 就不能用了, 写一起的话就可以
[此贴子已经被作者于2015/6/15 10:44:34编辑过]
|
||
-- 作者:wangyinming -- 发布时间:2015/6/15 10:49:00 -- Dim t As Table = Tables("加硫") Dim g As Subtotalgroup t.SubtotalGroups.Clear() t.GroupAboveData = False t.TreeVisible = True t.SpillNode = True g = New Subtotalgroup g.Aggregate = AggregateEnum.Sum g.GroupOn = "姓名" g.TotalOn = "生产数,稼动时间,产品时间" g.Caption = "{0} 小计" t.SubtotalGroups.Add(g) g = New Subtotalgroup g.Aggregate = AggregateEnum.Sum g.GroupOn = "*" g.TotalOn = "生产数,稼动时间,产品时间" g.Caption = "总计" g.upto = True t.SubtotalGroups.Add(g) t.Subtotal() 加在怎么加呢条件呢
|