Dim doc As New PrintDoc '定义一个新报表
Dim rt As New prt.RenderTable '定义一个新表格
Dim ri As New prt.RenderText '定义一个文本对象
Dim tb As Table = Tables("出库单.出库明细")
Dim ColNames As String() = New String(){"物料代码","类别","物料名称","规格型号","单位","单价","数量","金额","备注"} '要填入内容
doc.PageSetting.Width = 240 '纸张宽度为100毫米
doc.PageSetting.Height = 140
Doc.PageSetting.LeftMargin = 15 '设置左边距
Doc.PageSetting.RightMargin = 15 '设置右边距
Doc.PageSetting.TopMargin = 25 '设置上边距
Doc.PageSetting.BottomMargin = 20 '设置下边距
rt.SplitHorzBehavior = prt.SplitBehaviorEnum.SplitIfNeeded '表格宽度超出页宽时,可以水平换页
rt.Style.Font = tb.Font
For c As Integer = 0 To ColNames.Length - 1 '逐列设置和填入内容
rt.Cells(0,c).Text = ColNames(c) '列名作为标题
rt.Cells(0,c).Style.TextAlignHorz = prt.AlignHorzEnum.Center '标题内容水平居中
rt.Cells(0,c).Style.Font = New Font("楷体", 11, FontStyle.Bold) '标题内容
rt.Cols(c).Width = tb.Cols(ColNames(c)).PrintWidth '列宽等于实际列宽
If tb.Cols(ColNames(c)).IsNumeric OrElse tb.Cols(ColNames(c)).IsDate Then '如果是数值或日期列
rt.Cols(c).Style.TextAlignHorz = prt.AlignHorzEnum.Right '数据水平靠右
End If
For r As Integer = 0 To tb.Rows.Count -1 '开始填入该列内容
rt.Cells(r + 1, c).Text = tb.Rows(r)(ColNames(c))
Next
Next
ri = New prt.RenderText
ri.Style.FontSize = 14
ri.Style.FontBold = True
ri.Style.Spacing.Bottom = 5
ri.Text = "XXX公司出货订单"
ri.Style.TextAlignHorz = prt.AlignHorzEnum.Center
doc.Body.Children.Add(ri) '这里将需要加入什么代码才能实现分第二,三,四,,,,张表都统一一个标题.
rt.Style.Gridlines.All = New prt.Linedef(Color.Gray) '灰色网格线
rt.CellStyle.Spacing.All = 0.5 '单元格内距设为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()