比较笨,想很久才理解甜老师的意思,我重写了一下,确实 这样简单很多
Dim doc As New PrintDoc '定义一个报表
Dim rt As New prt.RenderTable() '定义一个表格对象
Dim rx As New prt.RenderText() '定义一个文本对象
rt.Style.GridLines.All = New prt.Linedef
Dim tb As Table = Tables("选定排单明细")
Dim Rows As List(Of DataRow)
Dim doc As New PrintDoc '定义一个报表
Dim rt As New prt.RenderTable() '定义一个表格对象
Dim rx As New prt.RenderText() '定义一个文本对象
rt.Style.GridLines.All = New prt.Linedef
Dim tb As Table = Tables("选定排单明细")
Dim Rows As List(Of DataRow)
Dim dh As List(of String) = tb.DataTable.GetValues("排单单号")
Doc.PageSetting.LeftMargin = 10 '设置左边距
Doc.PageSetting.RightMargin = 10 '设置右边距
Doc.PageSetting.TopMargin = 10 '设置上边距
Doc.PageSetting.BottomMargin = 10 '设置下边距
rt.CellStyle.Spacing.All = 2
'Doc.Columns.Add() '增加第一栏
'Doc.Columns.Add()
'
For Each dh1 As String In dh
Dim kh As List(Of String) = tb.DataTable.GetValues("物货其他","排单单号 = '"& dh1 & "'")
rt.BreakAfter = prt.BreakEnum.Page
rt = New prt.RenderTable
rt.Cells(0,0).text = format(Date.Today().AddDays(1),"yyyy年MM月dd日") &"-" & "出货计划"
rt.Cells(0,0).SpanCols = 10 '合并第一行全部单元格,用于显示主标题
rt.Cells(0,0).Style.TextAlignHorz = prt.AlignHorzEnum.Center '主标题居中
rt.Cells(0,0).Style.Font = New Font("微软雅黑", 16, FontStyle.Bold)
rt.Cells(1,0).text = " 第[PageNo]页,共[PageCount]页"
rt.Cells(1,0).SpanCols = 10 '合并第二行全部单元格,用于显示副标题
rt.Cells(1,0).Style.TextAlignHorz = prt.AlignHorzEnum.Center
rt.Cells(1,0).Style.Font = New Font("微软雅黑", 10, FontStyle.Bold)
rt.Rows(1).Height = 8
rt.cells(2,0).text = "排单时间:" & Date.Today()
rt.Cells(2,0).SpanCols = 2 '合并0-1,用于显示排单时间,车号,司机.时间点
rt.cells(2,2).text = "排单单号:" & dh1
rt.Cells(2,2).SpanCols = 3 '合并2-3,排单单号
rt.cells(2,5).text = "车号:" & "15620"
rt.Cells(2,5).SpanCols = 2
rt.cells(2,7).text = "司机:" & "梁锋"
rt.Cells(2,7).SpanCols = 2
rt.cells(2,9).text = "早上"
rt.Rows(2).Height = 10
rt.RowGroups(0,3).Header = prt.TableHeaderEnum.All
For p As Integer = 0 To 9
rt.Cells(2,p).Style.Font = New Font("微软雅黑", 9, FontStyle.Bold)
Next
Doc.body.Children.Add(rt)
For Each kh1 As String In kh
rt = New prt.RenderTable
rx = New prt.RenderText
rx.Style.FontSize = 10
rx.Style.FontBold = True
rx.Style.Spacing.Bottom = 2
rx.Text = "客户: " & kh1
doc.Body.Children.Add(rx)
Rows = tb.DataTable.Select("[物货其他] = '" & kh1 & "'and [排单单号] = '"& dh1 & "'")
For c As Integer = 0 To 2
'rt.Cells(4,c).Text = tb.Cols(c).Name
rt.Cols(c).Width = tb.Cols(c).PrintWidth
Dim y As Integer = Round2((Rows.Count)/3,0)
For r As Integer = 0 To y -1
rt.Cells(r + 4, c).Text = rows(r)(tb.Cols(c).Name)
Next
For p As Integer = y To y*2-1
rt.Cells(p-y+4, c+3).Text = rows(p)(tb.Cols(c).Name)
Next
For o As Integer = y*2 To Rows.Count-1
rt.cells(o-y*2+4,c+6).text = Rows(o)(tb.Cols(c).name)
Next
Next
Doc.body.Children.Add(rt)
Next
Next
doc.Preview()