回复4楼,我测试可以的,如果你的不行就肯定是代码哪里写错了,再调试一下。
Dim doc As New PrintDoc '定义一个报表
Dim rx As New prt.RenderTable
rx.Cells(0,0).Text = Date.Today
rx.Cells(0,1).Text = "抗震救灾专题"
rx.Cells(0,2).Text = "第[PageNo]页,共[PageCount]页"
rx.Cols(0).Style.TextAlignHorz = prt.AlignHorzEnum.Left
rx.Cols(1).Style.TextAlignHorz = prt.AlignHorzEnum.Center
rx.Cols(2).Style.TextAlignHorz = prt.AlignHorzEnum.right
rx.Style.Borders.Bottom = New prt.LineDef '设置底边框
rx.CellStyle.Spacing.Bottom = 0.5 '底端内容缩进0.5毫米
rx.Style.FontSize = 8 '字体大小为8磅
Doc.PageHeader = rx '作为页眉使用
Dim rt As New prt.RenderTable() '定义一个表格对象
doc.Body.Children.Add(rt) '将表格对象加入到报表中
rt.Style.GridLines.All = New prt.Linedef '设置网格线
rt.CellStyle.Spacing.All = 1 '内容距离网格线1毫米
'设置主标题
rt.Cells(0,0).text = "主标题内容"
rt.Cells(0,0).SpanCols = 6 '合并第一行全部单元格,用于显示主标题
rt.Cells(0,0).Style.TextAlignHorz = prt.AlignHorzEnum.Center '主标题居中
rt.Cells(0,0).Style.Font = New Font("宋体", 16, FontStyle.Bold) '设置主标题字体
rt.Rows(0).Style.Borders.All = New prt.LineDef("0mm", Color.white) '去掉第一行的网格线
'设置副标题
rt.Cells(1,0).text = " 副标题内容" '通过左边空格数量来调整副标题位置
rt.Cells(1,0).SpanCols = 6 '合并地二行全部单元格,用于显示副标题
rt.Cells(1,0).Style.TextAlignHorz = prt.AlignHorzEnum.Center '副标题内容居中
rt.Rows(1).Style.Borders.All = New prt.LineDef("0mm", Color.white) '去掉第二行的网格线
rt.Rows(1).Style.Borders.Bottom = New prt.Linedef '恢复第二行底端的网格线
rt.Rows(1).Height = 8 '设置第二行的高度,拉开和表格主体的距离.
'设置列标题
rt.cells(2,0).SpanCols = 3 '合并第一行前三个单元格
rt.Cells(2,3).SpanCols = 3 '合并第一行最后三个单元格
rt.cells(2,0).Text = "第一季度" '设置第一行第一个单元格的内容
rt.Cells(2,3).Text = "第二季度" '设置第一行第四个单元格的内容
rt.Cells(3,0).Text= "华东"
rt.Cells(3,1).Text = "华南"
rt.Cells(3,2).Text = "华北"
rt.Cells(3,3).Text= "华东"
rt.Cells(3,4).Text = "华南"
rt.Cells(3,5).Text = "华北"
rt.RowGroups(2,2).Style.BackColor = Color.LightGray '第三第四行的颜色设为灰色
rt.RowGroups(2,2).Style.TextAlignHorz = prt.AlignHorzEnum.Center '第三第四行的文本水平居中
rt.RowGroups(2,2).Style.TextAlignVert = prt.AlignVertEnum.Center '第三第四行的文本垂直居中
rt.RowGroups(0,4).Header = prt.TableHeaderEnum.All '前四行作为表头
'给表格增加行测试效果
For i As Integer = 2 To 100 '增加100行
rt.Cells(i + 2, 0).Text = i
Next
doc.Preview() '预览