直接进行统计
要打印统计数据,并不一定要借助CrossTableBuilder或CrossTableBuilder来生成一个统计表,我们完全可以在报表生成的过程中进行统计。
例如下面的代码,直接打印出不同产品的销售数量和金额,没有借助任何统计表:
Dim
Names
As List(Of
String) =
Tables("订单").DataTable.GetValues("产品")
Dim doc As
New PrintDoc
Dim rt As
New prt.RenderTable
rt.Cells(0,0).Text =
"产品"
rt.Cells(0,1).Text =
"订购次数"
rt.Cells(0,2).Text =
"数量"
rt.Cells(0,3).Text =
"金额"
For i As
integer =
0
To Names.Count -1
rt.Cells(i+1,0).Text=
Names(i)
rt.Cells(i+1,1).Text =
Tables("订单").DataTable.Compute("Count(日期)","产品='"
& Names(i) & "'")
rt.Cells(i+1,2).Text =
Tables("订单").DataTable.Compute("Sum(数量)","产品='"
& Names(i) & "'")
rt.Cells(i+1,3).Text =
Tables("订单").DataTable.Compute("Sum(金额)","产品='"
& Names(i) & "'")
Next
rt.Style.Gridlines.All = New prt.Linedef(Color.Gray)
'灰色网格线
rt.CellStyle.Spacing.All =
1
'内容距离网格线1毫米
rt.Rows(0).Style.TextAlignHorz
= prt.AlignHorzEnum.Center '第一行内容水平居中
doc.Body.Children.Add(rt)
doc.Preview()
打印结果:
本页地址:http://www.foxtable.com/webhelp/topics/1240.htm