Dim doc As New PrintDoc
Dim rx As New prt.RenderText
rx.Text = "对账明细"
rx.Style.Font = New Font("宋体", 16, FontStyle.Bold)
rx.Style.TextAlignHorz = prt.AlignHorzEnum.Center
rx.Style.Spacing.Bottom = 6
Doc.body.Children.Add(rx)
Dim rt As New Prt.RenderTable
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
Dim ii As Integer = 2 '第一页产品数
tbl.Filter = "[日期] >= #1/1/1999# And [日期] <= #2/28/1999#"
For Each pd As String In pds '分产品打印
If pd =pds(ii) Then
rt.BreakAfter = prt.BreakEnum.Page '换页
doc.Body.Children.Add(rt)
rt = New Prt.RenderTable
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
cnt = 0
'MessageBox.show(pd) ' Exit For
End If
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()