以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 通用打印代码如何在第二页继续打印标题和表头? (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=153174) |
-- 作者:nxhylczh -- 发布时间:2020/8/3 9:15:00 -- 通用打印代码如何在第二页继续打印标题和表头? Dim doc As New
PrintDoc
\'定义一个新报表 |
-- 作者:有点蓝 -- 发布时间:2020/8/3 9:24:00 -- 默认就是这样的?测试过? |
-- 作者:nxhylczh -- 发布时间:2020/8/3 11:10:00 -- 标题和表头,你默认打印的是表头,没有标题! |
-- 作者:有点蓝 -- 发布时间:2020/8/3 11:17:00 -- 自己补上呗:http://www.foxtable.com/webhelp/topics/2735.htm |
-- 作者:nxhylczh -- 发布时间:2020/8/3 11:58:00 -- Dim tb As Table = args(0) Dim MainTitle As String = args(1) Dim SubTitle As String =args(2) Dim HearRows As Integer =0 If SubTitle ="" Then HearRows =1 Else HearRows =2 End If Dim doc As New PrintDoc \'定义一个新报表 Dim rt As New prt.RenderTable \'定义一个新表格 Dim ColNames As New List(Of String) For Each cl As Col In tb.Cols \'排除隐藏列 If cl.Visible And cl.Name<>"选择" Then ColNames.Add(cl.Name) End If Next rt.Width = "Auto" \'表格宽度为自动,也就是等于各列设置宽度之和 rt.SplitHorzBehavior = prt.SplitBehaviorEnum.SplitIfNeeded \'表格宽度超出页宽时,可以水平换页 rt.Style.Font = tb.Font \'设置主标题 rt.Cells(0,0).text = MainTitle rt.Cells(0,0).SpanCols = ColNames.Count \'合并第一行全部单元格,用于显示主标题 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) \'去掉第一行的网格线 If SubTitle <>"" Then \'设置副标题 rt.Cells(1,0).text = SubTitle \'通过左边空格数量来调整副标题位置 rt.Cells(1,0).SpanCols = ColNames.Count \'合并地二行全部单元格,用于显示副标题 rt.Cells(1,0).Style.TextAlignHorz = prt.AlignHorzEnum.Left \'副标题内容居中 rt.Cells(1,0).Style.Font = New Font("微软雅黑", 10, FontStyle.Bold) \'设置主标题字体 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 \'设置第二行的高度,拉开和表格主体的距离. End If For c As Integer = 0 To ColNames.Count - 1 \'逐列设置和填入内容 rt.Cells(0,c).Text = ColNames(c) \'列名作为标题 rt.Cells(0,c).Style.TextAlignHorz = prt.AlignHorzEnum.Center \'标题内容水平居中 rt.Cols(c).Width = tb.Cols(ColNames(c)).PrintWidth \'列宽等于实际列宽 If tb.Cols(ColNames(c)).IsNumeric OrElse tb.Cols(ColNames(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 + 1+ HearRows, c).Text = tb.Rows(r)(ColNames(c)) Next Next rt.Style.Gridlines.All = New prt.Linedef(Color.Gray) \'灰色网格线 rt.CellStyle.Spacing.All = 0.5 \'单元格内距设为0.5毫米 rt.Rows(0).Style.TextAlignHorz = prt.AlignHorzEnum.Center \'第一行内容水平居中 rt.RowGroups(0,1).Header = prt.TableHeaderEnum.All \'利用行组,将第一行设为表头. doc.Body.Children.Add(rt) \'将表格加入到报表 doc.Preview() 老师 不知道那里出错了
[此贴子已经被作者于2020/8/3 11:59:36编辑过]
|
-- 作者:有点蓝 -- 发布时间:2020/8/3 13:34:00 -- rt.Rows(0).Style.Borders.All = New prt.LineDef("0mm", Color.white) \'去掉第一行的网格线 rt.Rows(0).Style.Borders.Bottom = New prt.LineDef(Color.Gray)
|
-- 作者:nxhylczh -- 发布时间:2020/8/3 14:17:00 -- 打印出来没有表头和标题 [此贴子已经被作者于2020/8/3 14:19:14编辑过]
|
-- 作者:有点蓝 -- 发布时间:2020/8/3 14:42:00 -- …… For c As Integer = 0 To ColNames.Count - 1 \'逐列设置和填入内容 rt.Cells(1,c).Text = ColNames(c) \'列名作为标题 rt.Cells(1,c).Style.TextAlignHorz = prt.AlignHorzEnum.Center \'标题内容水平居中 rt.Cols(c).Width = tb.Cols(ColNames(c)).PrintWidth \'列宽等于实际列宽 If tb.Cols(ColNames(c)).IsNumeric OrElse tb.Cols(ColNames(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 + 1+ HearRows, c).Text = tb.Rows(r)(ColNames(c)) Next Next rt.Style.Gridlines.All = New prt.Linedef(Color.Gray) \'灰色网格线 rt.CellStyle.Spacing.All = 0.5 \'单元格内距设为0.5毫米 rt.Rows(0).Style.TextAlignHorz = prt.AlignHorzEnum.Center \'第一行内容水平居中 rt.RowGroups(0,2).Header = prt.TableHeaderEnum.All \'利用行组,将第一行设为表头. doc.Body.Children.Add(rt) \'将表格加入到报表 doc.Preview() |