试试这个:
Dim doc As New Printdoc
Dim rx As new prt.RenderText
Dim prs As Integer = 9 '每页7行
Dim tb As Table = Tables("订单.订单明细")
Dim sum1 As Double = 0
Dim sum2 As Double = 0
Dim rs As Integer = Tables("订单.订单明细").Rows.Count
rx.text =" 订单编号: " & Tables("订单").Current("订单编号")
rx.Style.TextAlignHorz = prt.AlignHorzEnum.Center '水平居中
rx.Style.Font = New Font("宋体", 16, FontStyle.Bold)
rx.Style.Borders.Bottom = New prt.LineDef(1, Color.Green) '设置底边框
rx.Style.Padding.Bottom = 5'底端内容缩进0.5毫米
Doc.PageHeader = rx
For p As Integer = 0 To math.Ceiling(rs/prs) - 1
Dim rt As New prt.RenderTable() '定义一个表格对象
rt.Cols.Count = 4 '设置rt行列数
rt.Rows.Count = 9
rt.Height = 130
For i As Integer = 0 To 13
rt.Rows(i).Height = 10 '设置rt行高
Next
rt.Cells(0,0).Text = "产品" '设置rt表头
rt.Cells(0,1).Text = "单价"
rt.Cells(0,2).Text = "数量"
rt.Cells(0,3).Text = "金额"
For r As Integer = p * prs To math.min(rs- 1,( p + 1) * prs - 1)
rt.Cells(r - p * prs + 1, 0).Text = tb.rows(r)("产品")
rt.Cells(r - p * prs + 1, 1).Text = tb.rows(r)("单价")
rt.Cells(r - p * prs + 1, 2).Text = tb.rows(r)("数量")
rt.Cells(r - p * prs + 1, 3).Text = tb.rows(r)("金额")
Next
sum1 = 0
For r1 As Integer = p * prs To math.min(rs - 1,( p + 1) * prs - 1)
sum1 =sum1 + tb.rows(r1)("数量")
Next
If p < math.Ceiling(rs/ prs) - 1
rt.BreakAfter = prt.BreakEnum.Page
End If
rt.Rows(0).Style.Borders.bottom = New prt.Linedef '设置rt行格式
rt.Rows(1).Style.Borders.bottom = New prt.Linedef
rt.Rows(2).Style.Borders.bottom = New prt.Linedef
rt.Rows(3).Style.Borders.bottom = New prt.Linedef
rt.Rows(4).Style.Borders.bottom = New prt.Linedef
rt.Rows(5).Style.Borders.bottom = New prt.Linedef
rt.Rows(6).Style.Borders.bottom = New prt.Linedef
rt.Rows(7).Style.Borders.bottom = New prt.Linedef
rt.Rows(8).Style.Borders.bottom = New prt.Linedef
rt.Rows(9).Style.Borders.bottom = New prt.Linedef
rt.Rows(prs+1)(2).text = " 数量: " & sum1
rt.Style.TextAlignVert = prt.AlignVertEnum.Center
rt.Cells(prs+3,0).SpanCols = 4
rt.Rows(prs+3)(0).text = " 白色 深红 浅蓝 浅黄 浅绿 浅红 "
rt.Style.TextAlignHorz = prt.AlignHorzEnum.Center '水平居中
rt.Rows(prs+3)(0).Style.Font = New Font("宋体", 12, FontStyle.Bold)
doc.Body.Children.Add(rt)
Next
doc.Preview