老师好,在转换成PDF时标头能合并吗。此主题相关图片如下:2024-07-19 10 12 29.png
红线划出的表头能合并吗?
Dim dlg As New SaveFileDialog
Dim cnt As Integer
dlg.Filter= "pdfl文件|*.pdf"
dlg.FileName = user.name & "_Label1.pdf"
If dlg.ShowDialog = DialogResult.Ok Then
Dim doc As New PrintDoc '定义一个新报表
Dim rt As New prt.RenderTable '定义一个新表格
' Dim tb As Table = Tables("进销存")
Dim tb As Table = Tables("水电气使用数据查询_Table1")
rt.Width = "Auto" '表格宽度为自动,也就是等于各列设置宽度之和
doc.PageSetting.Landscape = True '横向打印
rt.SplitHorzBehavior = prt.SplitBehaviorEnum.SplitIfNeeded '表格宽度超出页宽时,可以水平换页
'-------------------------导出所有列不包括隐藏列----------------------------------------
rt.Style.Font = new Font("楷体", tb.Font.Size)
Dim idx As Integer = 0
For c As Integer = 0 To tb.Cols.Count -1 '逐列设置和填入内容
If tb.Cols(c).visible = False Then Continue For
rt.Cells(0,idx).Text = tb.Cols(c).Name '列名作为标题
rt.Cells(0,idx).Style.TextAlignHorz = prt.AlignHorzEnum.Center '标题内容水平居中
rt.Cols(idx).Width = tb.Cols(c).PrintWidth '列宽等于实际列宽
If tb.Cols(c).IsNumeric OrElse tb.Cols(c).IsDate Then '如果是数值或日期列
rt.Cols(idx).Style.TextAlignHorz = prt.AlignHorzEnum.Right '数据水平靠右
End If
For r As Integer = 0 To tb.Rows.Count -1 '开始填入该列内容
rt.Cells(r + 1, idx).Text = tb(r,c)
Next
idx += 1
Next
老师,修改后还是不行。黄色标出的是新加代码。
Dim dlg As New SaveFileDialog
Dim cnt As Integer
dlg.Filter= "pdfl文件|*.pdf"
dlg.FileName = user.name & "_Label1.pdf"
If dlg.ShowDialog = DialogResult.Ok Then
Dim doc As New PrintDoc '定义一个新报表
Dim rt As New prt.RenderTable '定义一个新表格
' Dim tb As Table = Tables("进销存")
Dim tb As Table = Tables("水电气使用数据查询_Table1")
Dim hd As Integer = tb.HeaderRows '获得表头的层数
tb.CreateReportHeader(rt,True)
rt.Width = "Auto" '表格宽度为自动,也就是等于各列设置宽度之和
doc.PageSetting.Landscape = True '横向打印
rt.SplitHorzBehavior = prt.SplitBehaviorEnum.SplitIfNeeded '表格宽度超出页宽时,可以水平换页
'-------------------------导出所有列不包括隐藏列----------------------------------------
rt.Style.Font = new Font("楷体", tb.Font.Size)
Dim idx As Integer = 0
For c As Integer = 0 To tb.Cols.Count -1 '逐列设置和填入内容
If tb.Cols(c).visible = False Then Continue For
rt.Cells(0,idx).Text = tb.Cols(c).Name '列名作为标题
rt.Cells(0,idx).Style.TextAlignHorz = prt.AlignHorzEnum.Center '标题内容水平居中
rt.Cols(idx).Width = tb.Cols(c).PrintWidth '列宽等于实际列宽
If tb.Cols(c).IsNumeric OrElse tb.Cols(c).IsDate Then '如果是数值或日期列
rt.Cols(idx).Style.TextAlignHorz = prt.AlignHorzEnum.Right '数据水平靠右
End If
For r As Integer = 0 To tb.Rows.Count -1 '开始填入该列内容
rt.Cells(r + 1, idx).Text = tb(r,c)
Next
idx += 1
Next