不可能不符,再改一下,请认真测试。
Dim doc As New PrintDoc
Dim rt As Prt.RenderTable
Dim rx As prt.RenderText
Dim tbl As Table = Tables("客户")
Dim ColNames As String() = New String(){"客户", "地址", "城市"}
Dim Rows As List(Of DataRow)
Dim Regions As List(Of String) = tbl.DataTable.GetValues("地区", tbl.Filter)
doc.Pagesetting.LandScape = True
For Each Region As String In Regions
rx = New prt.RenderText
rx.Style.FontSize = 14
rx.Style.FontBold = True
rx.Style.Spacing.Bottom = 2
rx.Text = "地区: " & Region
doc.Body.Children.Add(rx)
rt = New prt.RenderTable
rt.Style.Font = Tables("客户").Font
rt.Style.TextAlignVert = prt.AlignVertEnum.Center
rt.Style.GridLines.All = New prt.LineDef(0.3,Color.LightGray)
rt.Style.Spacing.Bottom = 5
rt.CellStyle.Spacing.All = 1
rt.Style.Font = tbl.Font
Rows = tbl.DataTable.Select("[地区] = '" & Region & "'")
rt.Cells(0,0).Text = "客户ID"
Dim filter As String = tbl.Filter
tbl.Filter = "日期 = #" & Date.Today & "#"
For r As Integer = 0 To tbl.Rows.Count -1 '开始填入该列内容
rt.Cols(0).Width = 5
Dim fdr As DataRow = DataTables("客户表").Find("客户 = '" & Tbl.Rows(r)("客户").split("-")(0) & "'")
If fdr IsNot Nothing Then
rt.Cells(r + 1, 0).Text = fdr("客户Id")
Else
rt.Cells(r + 1, 0).Text = ""
End If
Next
For c As Integer = 0 To ColNames.Length - 1 '逐列设置和填入内容
rt.Cells(0,c+1).Text = ColNames(c) '列名作为标题
rt.Cells(0,c+1).Style.TextAlignHorz = prt.AlignHorzEnum.Center '标题内容水平居中
rt.Cols(c+1).Width = tbl.Cols(ColNames(c)).PrintWidth '列宽等于实际列宽
If tbl.Cols(ColNames(c)).IsNumeric OrElse tbl.Cols(ColNames(c)).IsDate Then '如果是数值或日期列
rt.Cols(c+1).Style.TextAlignHorz = prt.AlignHorzEnum.Right '数据水平靠右
End If
For r As Integer = 0 To tbl.Rows.Count -1 '开始填入该列内容
rt.Cells(r + 1, c+1).Text = tbl.Rows(r)(ColNames(c))
Next
Next
tbl.Filter = filter
rt.RowGroups(0,1).Header = prt.TableHeaderEnum.All
doc.Body.Children.Add(rt)
Next
doc.preview()