Dim doc As New Printdoc
Dim rx As prt.RenderText
Dim rt As prt.RenderTable
Dim Rows As List(Of DataRow)
Dim tbl As Table = Tables("销售主表")
Dim tb As Table = Tables("销售明细")
'选定区域的
With Tables("销售主表")
If .TopPosition > -1 Then '如果选定区域包括数据行
For i As Integer = .TopPosition To .BottomPosition
Dim prs As Integer = 5
Dim cols() As String = {"产品", "客户", "雇员", "单价", "折扣", "数量"}
For Each pr As Row In tbl.Rows
Rows = tb.DataTable.select("客户='" & pr("公司名称") & "'")
For p As Integer = 0 To math.Ceiling(Rows.Count / prs) - 1
rx = New prt.RenderText
' '
rx.Style.FontSize = 14
rx.Style.FontBold = True
rx.Style.Spacing.Bottom = 5
rx.Text = "公司名称: " & pr("公司名称") & " - " & (p + 1)
doc.Body.Children.Add(rx)
rt = New prt.RenderTable
rt.Style.TextAlignHorz = prt.AlignHorzEnum.Center
rt.Style.TextAlignVert = prt.AlignVertEnum.Center
rt.Style.Borders.Bottom = New prt.LineDef(0.3, Color.LightGray)
rt.CellStyle.Spacing.All = 1
rt.Cols.Count = 4
For j As Integer = 0 To cols.Length - 1 '打印标题
rt.Cells(0, j).Text = cols(j)
Next
rt.Cols(1).Width = 60 '指定
rt.rows(0).Style.Borders.Top = New prt.LineDef(1, Color.LightGray)
rt.rows(0).Style.Borders.Bottom = New prt.LineDef(1, Color.LightGray)
Dim sum As Double = 0
For r As Integer = p * prs To math.min(Rows.Count - 1, ( p + 1) * prs - 1)
sum += rows(r)("数量") '
For j As Integer = 0 To cols.Length - 1
rt.Cells(r - p * prs + 1, j).Text = rows(r)(cols(j))
Next
Next
If p = math.Ceiling(Rows.Count / prs) - 1 Then'
For r As Integer = Rows.Count To ( p + 1) * prs - 1 '
rt.Rows.Count = rt.Rows.Count + 1
rt.Rows(rt.Rows.count - 1)(0).text = " "
Next
End If
Dim cnt = rt.Rows.Count
doc.Body.Children.Add(rt)
rx = New prt.RenderText
rx.Style.FontBold = True
rx.Style.Spacing.Top = 3
rx.Text = "销售明细数目: " & Rows.Count
rx.Style.TextAlignHorz = prt.AlignHorzEnum.Right
rx.BreakAfter = prt.BreakEnum.Page '否则换页
doc.Body.Children.Add(rx)
Next
Next
Next
End If
End With
doc.Preview
我还是没搞定,请帮忙,谢谢