'页面设置
Dim doc As New PrintDoc '定义一个报表
Doc.PageSetting.LeftMargin = 15
Doc.PageSetting.BottomMargin = 15
Doc.PageSetting.TopMargin = 15
Doc.PageSetting.rightMargin = 15
Dim rm As prt.RenderEmpty '定一个空对象
doc.Pagesetting.LandScape = True
'设置页脚
Dim yj As New prt.RenderText '定义一个文本对象
yj = New prt.RenderText '设置文本对象的内容
yj.Text = "第[PageNo]页 共[PageCount]页" '设置文本内容
yj.Style.TextAlignHorz = prt.AlignHorzEnum.center '页脚中间对齐
yj.Style.Font = New Font("宋体", 10) '字体大小为10磅
yj.Style.Padding.Bottom = -10 '底端内容缩进10毫米
Doc.PageFooter = yj '作为页脚使用
Dim tbl8 As Table = Tables("劳保发放标准")
Dim rt8 As Prt.RenderTable
Dim rx8 As prt.RenderText
Dim Rows8 As List(Of DataRow)
'设置二级标题
rx8 = New prt.RenderText
rx8.Style.Font = New Font("宋体", 16)
rx8.Style.Spacing.Bottom = 5
Dim dr As String = Forms("mainform").controls("劳保发放企业名称").value
rx8.text = dr & vbcrlf & "劳动防护用品发放标准" '表标题显示企业名称
rx8.Style.TextAlignHorz = prt.AlignHorzEnum.Center '标题水平居中
doc.Body.Children.Add(rx8)
'设置表格样式
rt8 = New prt.RenderTable
rt8.Style.TextAlignVert = prt.AlignVertEnum.Center
rt8.Style.GridLines.All = New prt.LineDef(0.3,Color.blue)
rt8.Style.Spacing.Bottom = 5
rt8.CellStyle.Spacing.All = 1
rt8.Style.Font = New Font("宋体", 11)
'设置表格细节
Rows8 = tbl8.DataTable.Select("企业名称 Like '*" & Forms("mainform").controls("劳保发放企业名称").value & "*'“,"部门") '指定符合条件的行和排序方式
Dim nms8() As String = {"企业名称","部门","岗位","身份证号","所在部门","接害种类","查体类别","查体项目","查体日期","查体结论","查体机构"} '指定要显示的列即要打印的列
Dim caps() As String = {"序号","部门","岗位","身份证号","所在部门","接害种类","查体类别","查体项目","查体日期","查体结论","查体机构"} '自定义列名
For c As Integer = 0 To nms8.length - 1
Dim ary() As String = caps(c).split("|")
For i As Integer = 0 To ary.length-1
rt8.cells(i, c).text = ary(i)
Next '打印的列标题自定义
'rt8.Cells(0,c).Text = tbl8.Cols(nms8(c)).Name '使用原列名
rt8.Cells(0,c).Style.TextAlignHorz = prt.AlignHorzEnum.Center '标题内容水平居中
'rt8.Cols(c).Width = tbl8.Cols(c).PrintWidth '根据原表格确定列宽
rt8.Cols(0).Width = 15 '设置各列宽度
rt8.Cols(1).Width = 15
rt8.Cols(2).Width = 20
rt8.Cols(3).Width = 45
rt8.Cols(4).Width = 25
rt8.Cols(5).Width = 30
rt8.Cols(6).Width = 20
rt8.Cols(7).Width = 40
rt8.Cols(8).Width = 25
rt8.Cols(9).Width = 25
rt8.Cols(10).Width = 35
For r As Integer = 0 To Rows8.Count -1
If c=0 Then
rt8.Cells(r + 1, c).Text = r + 1 '增加了序号列,并自动填充
Else
rt8.Cells(r + 1, c).Text = rows8(r)(tbl8.Cols(nms8(c)).Name)
End If
Next
Next
rt8.RowGroups(0,1).Header = prt.TableHeaderEnum.All
doc.Body.Children.Add(rt8)
Doc.Preview() '预览报表