Foxtable(狐表)用户栏目专家坐堂 → 专业报表数据绑定,统计得到的数据再计算得到平均统计数如何写


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

主题:专业报表数据绑定,统计得到的数据再计算得到平均统计数如何写

美女呀,离线,留言给我吧!
annliu
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:婴狐 帖子:28 积分:291 威望:0 精华:0 注册:2011/12/16 17:00:00
专业报表数据绑定,统计得到的数据再计算得到平均统计数如何写  发帖心情 Post By:2013/6/26 17:41:00 [只看该作者]

打印这样一个报表

 

Dim doc As New PrintDoc '定义一个报表
doc.Stacking = prt.StackingRulesEnum.InlineLeftToRight
doc.PageSetting.LeftMargin = 15
doc.PageSetting.RightMargin = 15
Dim StartDate As Date
Dim EndDate As Date
With RibbonTabs("常用菜单")("生产报表")
    StartDate = .Items("StartDate").Value
    EndDate = .Items("EndDate").Value
End With
Dim rte As prt.RenderText '定义一个文本对象
rte = New prt.RenderText
rte.Text ="("& CStr( StartDate ) & "--" &  CStr( EndDate )&")"&"产值报表" '设置文本对象的内容
rte.Style.TextAlignHorz = prt.AlignHorzEnum.Center '水平居中
rte.Style.Font = New Font("宋体", 18, FontStyle.Bold)
rte.Style.Spacing.Bottom = 4 '设置下间隔为3毫米
doc.Body.Children.Add(rte) '将文本对象加入到报表

Tables("产品生产日报表").Filter = "[日期] >= #" & StartDate & "# And [日期] <= #" & EndDate & "#   "

Dim rx As New prt.RenderText
Dim rt As New prt.RenderTable
Dim ra As New prt.RenderArea
Dim Agg1 As New prt.DataBinding.Aggregate("净重")
Dim Agg2 As New prt.DataBinding.Aggregate("金额")
Dim Agg3 As New prt.DataBinding.Aggregate("平均实际吨价")
Dim Agg4 As New prt.DataBinding.Aggregate("净重小计")

rt.Style.Font = New Font("宋体", 10) '设置字体
rt.Style.GridLines.All = New prt.Linedef(Color.Gray)
rt.CellStyle.Spacing.All = 1
rt.Cols(0).Width = 10 '设置列宽
rt.Cols(1).Width = 10 '设置列宽
rt.Cols(2).Width = 10 '设置列宽
rt.Cols(3).Width = 10 '设置列宽
rt.Cols(4).Width = 10 '设置列宽
rt.Cols(5).Width = 10 '设置列宽

rt.Cells(0,0).Text = "产品分类"
rt.Cells(0,1).Text = "外来加工"
rt.Cells(0,2).Text = "币制"
rt.Cells(0,3).Text = "净重(KG)"
rt.Cells(0,4).Text = "金额"
rt.Cells(0,5).Text = "平均实际吨价"
rt.Cells(1,0).Text = "[Fields!产品分类.Value]"
rt.Cells(1,1).Text = "[Fields!外来加工.Value]"
rt.Cells(1,2).Text = "[Fields!币制.Value]"
rt.Cells(1,3).Text = "[Math.Round(Aggregates!净重.Value,2)]" 
rt.Cells(1,4).Text = "[Math.Round(Aggregates!金额.Value,2)]"
rt.Cells(1,5).Text = "[Math.Round(Aggregates!平均实际吨价.Value,2)]"
rt.Cells(2,0).Text = "[Fields!产品分类.Value]" & "小计"
rt.Cells(2,0).SpanCols = 3
rt.Cells(2,3).Text = "[Math.Round(Aggregates!净重小计.Value,2)]"
With rt.RowGroups(1,1)
    .DataBinding.DataSource = BindTables("产品生产日报表")
    .DataBinding.Grouping.Expressions.Add("Fields!产品分类.Value")
    .DataBinding.Grouping.Expressions.Add("Fields!外来加工.Value")
    .DataBinding.Grouping.Expressions.Add("Fields!币制.Value")
    agg1.DataBinding = .DataBinding
    agg1.Running = 1
    agg1.Expressi
    doc.DataSchema.Aggregates.Add(agg1)
    agg2.DataBinding = .DataBinding
    agg2.Running = 1
    agg2.Expressi
    doc.DataSchema.Aggregates.Add(agg2)
 agg3.DataBinding = .DataBinding
    agg3.Running = 1
agg3.Func=1
    agg3.Expressi
    doc.DataSchema.Aggregates.Add(agg3)

End With
With rt.RowGroups(1,2)
    .DataBinding.DataSource = BindTables("产品生产日报表")
    .DataBinding.Grouping.Expressions.Add("Fields!产品分类.Value")
    agg4.DataBinding = .DataBinding
    agg4.Running = 1
    agg4.Expressi
    doc.DataSchema.Aggregates.Add(agg4)
End With
rt.RowGroups(1,1).DataBinding.DataSource = BindTables("产品生产日报表")
doc.body.Children.Add(rt)

doc.Preview() '预览doc.Preview() '预览

 

显示结果为

最后一列平均实际吨价 的值不对。现在是每个实际吨价的平均值。但是我其实需要的是 统计出来的金额除以统计出来的重量就可以了。要怎么改代码呢?

 回到顶部
帅哥哟,离线,有人找我吗?
狐狸爸爸
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:管理员 帖子:47448 积分:251048 威望:0 精华:91 注册:2008/6/17 17:14:00
  发帖心情 Post By:2013/6/26 18:05:00 [只看该作者]

你用的是绑定,只能在表中算好,再打印。

 回到顶部