开发指南中介绍两个实例代码
打印统计数据:
Dim dt As DataTable
Dim g As New GroupTableBuilder("统计表1", DataTables("订单"))
g.Groups.AddDef("产品")
g.Totals.AddDef("数量")
g.Totals.AddDef("金额")
dt = g.Build(True)
Dim doc As New PrintDoc
Dim rt As New prt.RenderTable
Dim Count As Integer = 0
For Each Col As DataCol In Dt.DataCols
rt.Cells(0,Count).Text = Col.Name
For r As Integer = 0 To dt.DataRows.Count - 1
rt.Cells(r +1,Count).Text = dt.DataRows(r)(Col.Name)
Next
Count = Count + 1
Next
rt.Style.Gridlines.All = New prt.Linedef(Color.Gray)
rt.CellStyle.Spacing.All = 1
rt.Rows(0).Style.TextAlignHorz = prt.AlignHorzEnum.Center
doc.Body.Children.Add(rt)
doc.Preview()
直接进行统计:
Dim dt As DataTable
Dim Names As List(Of String) = Tables("订单").DataTable.GetUniqueValues("","产品")
Dim doc As New PrintDoc
Dim rt As New prt.RenderTable
rt.Cells(0,0).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,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()
预览结果都一样:
产品 |
数量 |
金额 |
PD01 |
11290 |
171754.92 |
PD02 |
18200 |
296522.5 |
PD03 |
7000 |
61490 |
PD04 |
5480 |
102861 |
PD05 |
10400 |
19023.15 |
代码十分简单方便。
但我希望得到多层分组的统计表,如下:
产品 |
雇员 |
数量 |
金额 |
PD01小计 |
|
11290 |
171754.92 |
|
EP01 |
3100 |
47160.3 |
|
EP02 |
3500 |
53245.5 |
|
EP03 |
4050 |
61612.65 |
|
EP05 |
640 |
9736.47 |
PD02小计 |
|
18200 |
296522.5 |
|
EP01 |
|
|
|
EP02 |
|
|
|
EP04 |
|
|
|
.. |
|
|
PD03小计 |
|
7000 |
61490 |
|
EP01 |
|
|
|
EP03 |
|
|
|
EP04 |
|
|
|
… |
|
|
… |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
请教此代码应如何编?