生成表头以后,循环每一列的时候,修改一下表头不就行了?
Dim doc As New PrintDoc '定义一个新报表
Dim rt As New prt.RenderTable '定义一个新表格
Dim tb As Table = Tables("表A")
Dim hd As Integer = tb.Headerrows '获得表头的层数
rt.Width = "Auto" '表格宽度为自动,也就是等于各列设置宽度之和
rt.Style.Font = tb.Font
tb.CreateReportHeader(rt,False) '生成表头,包括所有列
For c As Integer = 0 To tb.Cols.Count -1 '逐列设置和填入内容
Dim ary() As String = tb.cols(c).Caption.split("_")
For i As Integer = 0 To ary.length - 1
rt.Cells(i, c).Text = ary(i)
Next
rt.Cols(c).Width = tb.Cols(c).PrintWidth '列宽等于实际列宽
If tb.Cols(c).IsNumeric OrElse tb.Cols(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 + hd, c).Text = tb(r,c)
Next
Next
rt.Style.Gridlines.All = New prt.Linedef(Color.Gray) '灰色网格线
rt.CellStyle.Spacing.All = 0.5 '单元格内距设为0.5毫米
rt.RowGroups(0, tb.HeaderRows).Header = prt.TableHeaderEnum.All '利用行组功能设置表头
doc.Body.Children.Add(rt) '将表格加入到报表
doc.Preview()