方法一:
Dim doc As New PrintDoc
Dim rt As New prt.RenderTable
Dim tb As DataTable = DataTables("订单")
Dim ColNames As String() = New String(){"产品", "客户","单价","折扣","数量","金额","日期"}
Dim MergeCols As Integer = 2 '指定要合并的列数
Dim drs = tb.Select("", "产品,客户") '根据合并列排序
rt.Width = "Auto"
rt.SplitHorzBehavior = prt.SplitBehaviorEnum.SplitIfNeeded
rt.Style.TextAlignVert = prt.AlignVertEnum.Center
rt.RepeatGridLinesVert = True '换页后重复表格线
For c As Integer = 0 To ColNames.Length - 1
Dim lr As Integer ' 用于保存合并区域的起始行
rt.Cells(0,c).Text = ColNames(c)
rt.Cells(0,c).Style.TextAlignHorz = prt.AlignHorzEnum.Center
If tb.datacols(ColNames(c)).IsNumeric OrElse tb.datacols(ColNames(c)).IsDate Then
rt.cols(c).Style.TextAlignHorz = prt.AlignHorzEnum.Right
End If
For r As Integer = 0 To drs.Count - 1
If c <= MergeCols - 1 Then '如果是要合并的列
Dim Merge As Boolean = True
If r = 0 Then
Merge = False
Else
For n As Integer = 0 To c
If drs(r)(ColNames(n)) <> drs(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 = drs(r)(ColNames(c))
rt.Cells(r + 1, c).VertSplitBehavior = prt.CellSplitBehaviorEnum.Copy '换页后重复单元格
lr = r + 1
End If
Else
rt.Cells(r + 1, c).Text = drs(r)(ColNames(c))
End If
Next
Next
rt.Style.Gridlines.All = New prt.Linedef(Color.Gray)
rt.CellStyle.Spacing.All = 0.5
rt.Rows(0).Style.TextAlignHorz = prt.AlignHorzEnum.Center
rt.RowGroups(0,1).Header = prt.TableHeaderEnum.All
doc.Body.Children.Add(rt)
doc.Preview()