'页面设置
Dim doc As New PrintDoc '定义一个报表
Doc.PageSetting.LeftMargin = 15
Doc.PageSetting.BottomMargin = 15
Doc.PageSetting.TopMargin = 15
Doc.PageSetting.rightMargin = 15
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.FontSize = 10 '字体大小为10磅
yj.Style.Padding.Bottom = -10 '底端内容缩进10毫米
Doc.PageFooter = yj '作为页脚使用
For Each ss As String() In DataTables("标准化自评打分").GetValues("企业名称|年度",Tables("标准化自评打分").Filter)
Dim rm As prt.RenderEmpty '定一个空对象
rm = new prt.RenderEmpty '定义一个新的空对象
rm.BreakBefore = prt.BreakEnum.Page '打印前换页
doc.Body.Children.Add(rm) '加入到报表中
Dim rw As DataRow = DataTables("标准化自评打分").Find("企业名称 = '" & ss(0) & "' And 年度 = '" & ss(1) & "'" & IIF(Tables("标准化自评打分").Filter > ""," and ","") & Tables("标准化自评打分").Filter)
If rw Is Nothing Then Continue For
Dim rt As New prt.RenderTable() '定义一个表格对象
Dim ra As New prt.RenderArea '定义一个容器
ra.SplitVertBehavior = prt.SplitBehaviorEnum.Never '禁止容器因为分页而被垂直分割
'设置标题
Dim rx8 As prt.RenderText
rx8 = New prt.RenderText
rx8.Style.FontSize = 16
rx8.Style.Spacing.Bottom = 5
Dim dr As String = forms("mainform").controls("考评企业名称").value
rx8.text = dr & vbcrlf & "山东省小微型企业安全标准化年度考评记录" '表标题显示企业名称
rx8.Style.TextAlignHorz = prt.AlignHorzEnum.Center '标题水平居中
Ra.Children.Add(rx8)
'doc.Body.Children.Add(rx8)
'设置表格样式
rt.Rows.Count = 2 '设置总行数
rt.Cols.Count = 4 '设置总列数
rt.Height = 24 '设置表格的高度
rt.Style.FontSize = 12 '大体大小为12磅
rt.Style.GridLines.All = New prt.LineDef(0.3,Color.blue)
rt.Rows(0).Height = 12
rt.Rows(1).Height = 12
rt.Cols(0).Width = 25 '设置列的宽度
rt.Cols(1).Width = 60
rt.Cols(2).Width = 25
rt.Cols(3).Width = 60
'设置表格样式
rt.CellStyle.Spacing.All = 1 '单元格内容缩进1毫米
rt.Style.Spacing.Bottom = 1 '和下一个资料卡的距离是5毫米
rt.Style.GridLines.All = New prt.Linedef '设置网格线
rt.Style.TextAlignHorz = prt.AlignHorzEnum.left '水平居中
rt.Style.TextAlignVert = prt.AlignVertEnum.Center '垂直居中
rt.Cells(0,0).Text= "企业名称"
rt.Cells(0,1).Text = rw("企业名称")
rt.Cells(0,2).Text= "考评日期"
rt.Cells(0,3).Text = rw("考评日期")
rt.Cells(1,0).Text= "考评组长"
rt.Cells(1,1).Text = rw("考评组长")
rt.Cells(1,2).Text= "考评组成员"
rt.Cells(1,3).Text = rw("考评组成员")
ra.Children.Add(rt) '加入到容器中
'Doc.Body.ChildRen.Add(ra) '将容器加入到报表中
'打印
Dim Rows8 As List(Of DataRow)
Dim rt8 As Prt.RenderTable
'设置表格样式
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 = tbl8.Font '字号
rt8.Style.FontSize = 10
'设置表格细节
Dim tbl8 As Table = Tables("标准化自评打分")
Rows8 = tbl8.DataTable.Select("企业名称 = '" & ss(0) & "' And 年度 = '" & ss(1) & "'" & IIF(Tables("标准化自评打分").Filter > ""," and ","") & Tables("标准化自评打分").Filter) '指定符合条件的行和排序方式
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 i8 As Integer = 0 To ary.length-1
rt8.cells(i8, c).text = ary(i8)
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 = 35
rt8.Cols(2).Width = 40
rt8.Cols(3).Width = 180
rt8.Cols(4).Width = 25
rt8.Cols(5).Width = 180
rt8.Cols(6).Width = 160
rt8.Cols(7).Width = 25
rt8.Cols(8).Width = 25
rt8.Cols(9).Width = 25
rt8.Cols(10).Width = 30
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
Ra.Children.Add(rt8)
doc.Body.Children.Add(ra)
Next
Doc.Preview() '预览
打印预览时,不分页
此主题相关图片如下:捕获.jpg