Dim doc As New PrintDoc
Dim rt As Prt.RenderTable
Dim rx As prt.RenderText
Dim tbl As Table = Tables("报价单明细")
Dim Rows As List(Of DataRow)
Dim Regions As List(Of String) = tbl.DataTable.GetValues("报价大类")
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
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 & "'")
Dim ColNames As String() = New String(){"报价序号","CODE","项目","二级项目","币种","金额","单位","税率","备注"}
Dim cn As String() = New String(){"NO.","CODE","项目","二级项目","币种","金额","单位","税率","备注"} ' 别名
Dim mc As Integer = 3 '合并前三个列
'tbl.Sort ="报价序号,CODE,项目"
For c As Integer = 0 To ColNames.Length - 1
Dim lr As Integer '用于保存合并区域的起始行
rt.Cells(0,c).Text = cn(c) '第一列使用别名
rt.Cells(0,c).Style.TextAlignHorz = prt.AlignHorzEnum.Center
rt.Cols(c).Width = tbl.Cols(c).PrintWidth
For r As Integer = 0 To Rows.Count -1
If c <= mc -1 Then '如果是要合并的列
Dim merge As Boolean = True
If r = 0 Then
merge = False
Else
For n As Integer = 0 To c
If Rows(r)(Colnames(n)) <> Rows(r-1)(Colnames(n))
merge = False
Exit For
End If
Next
End If
If merge Then
rt.cells(lr,c).SpanRows = rt.Cells(lr,c).SpanRows + 1
Else
rt.Cells(r + 1,c).Text = rows(r)(ColNames(c))
lr = r + 1
End If
Else
rt.Cells(r + 1,c).Text = rows(r)(ColNames(c))
End If
Next
Next
rt.RowGroups(0,1).Header = prt.TableHeaderEnum.All '将第一行作为表头.
doc.Body.Children.Add(rt)
Next
doc.preview()