Dim
doc
As New PrintDoc
Dim rt As
New Prt.RenderTable
Dim rx As
prt.RenderText
Dim cnt As
Integer
Dim tbl As
Table =
Tables("订单")
Dim drs As
List(Of
DataRow)
Dim pds As
List(Of
String)
= tbl.DataTable.GetValues("产品",tbl.Filter)
rt.Style.GridLines.All = New prt.LineDef(0.3,Color.LightGray)
rt.CellStyle.Spacing.All
= 1
rt.Style.Font = tbl.Font
For c
As
Integer
= 0
To
tbl.Cols.Count
- 1
'生成列标题
rt.Cells(0,c).Text
= tbl.Cols(c).Name
rt.Cols(c).Width
= tbl.Cols(c).PrintWidth
Next
For Each pd As
String
In pds '分产品打印
If tbl.Filter > ""
Then
drs
= tbl.DataTable.Select("产品
= '" &
pd
&
"' And "
&
tbl.Filter)
Else
drs
= tbl.DataTable.Select("产品
= '" &
pd
&
"'" )
End If
For Each dr
As DataRow
In drs '逐行打印此产品的订单
cnt = rt.Rows.Count
For c
As Integer
= 0
To tbl.Cols.Count
- 1
rt.Cells(cnt,
c).Text
= dr(tbl.Cols(c).Name)
Next
Next
cnt = rt.Rows.Count
rt.Cells(cnt,
0).Text
= "小计 "
&
pd '打印产品的小计
rt.Cells(cnt,5).Text
= tbl.compute("Sum(数量)",
"产品 = '"
&
pd &
"'")
Next
cnt = rt.Rows.Count
rt.Cells(cnt, 0).Text
= "合计 "
'打印合计
rt.Cells(cnt, 5).Text
= tbl.compute("Sum(数量)")
doc.Body.Children.Add(rt)
doc.preview()
代码说明:
上面的代码中,每次要打印一个新行,都先通过下面的代码获得已经打印的行数,并保存在变量cnt中:
cnt = rt.Rows.Count
假定已经打印了9行,编号为0到8,执行上面的代码,cnt的值就等于9。
显然下一个订单或小计,应该打印在编号为9的行,也就是编号为cnt的行。