以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]请教专业报表设计 页眉页脚分页循环打印  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=163041)

--  作者:lds
--  发布时间:2021/4/21 17:28:00
--  [求助]请教专业报表设计 页眉页脚分页循环打印
图片点击可在新窗口打开查看




图片点击可在新窗口打开查看


Dim doc As New PrintDoc  \'定义一个报表
Dim rt As prt.RenderTable\'定义一个表格对象

Dim tb As Table = Tables("主表.明细表")
Dim tbl As Table = Tables("主表")

doc.PageSetting.Width = 241  \'纸张宽度为200毫米
doc.PageSetting.Height = 93 \'纸张高度为170毫米
doc.AutoRotate = False  \'如果纸张的宽度超过高度,要加上这行代码

doc.PageSetting.TopMargin= 1
doc.PageSetting.BottomMargin =5
doc.PageSetting.LeftMargin= 5
doc.PageSetting.RightMargin =5

Dim rt1 As New prt.RenderText 
rt1 = New prt.RenderText \'设置文本对象的内容
rt1.Text = "页数[PageNo]/[PageCount]" \'设置文本内容
rt1.Style.TextAlignHorz = prt.AlignHorzEnum.Right \'靠右对齐

rt1.Style.Padding.Bottom = 0.5 \'底端内容缩进0.5毫米
rt1.Style.FontSize = 16 \'字体大小为8磅
Doc.PageHeader = rt1 \'作为页眉使用

\'设置主标题
rt = New prt.RenderTable
rt.BreakBefore = prt.BreakEnum.Page \'另起一页再打印
rt.Style.GridLines.All = New prt.Linedef  \'设置网格线
rt.CellStyle.Spacing.All = 1 \'内容距离网格线1毫米
rt.Cells(0,0).text = "xxx采购入库单"

rt.Cells(0,0).SpanCols = 10 \'合并第一行全部单元格,用于显示主标题
rt.Cells(0,0).Style.TextAlignHorz = prt.AlignHorzEnum.Center \'主标题居中
rt.Cells(0,0).Style.Font = New Font("宋体", 16, FontStyle.Bold) \'设置主标题字体


\'设置副标题
rt.Cells(1,0).text ="单号:" & tbl.Current("单号")  \'通过左边空格数量来调整副标题位置
rt.Cells(1,0).Spancols = 3 \'合并第二行全部单元格,用于显示副标题
rt.Cells(1,0).Style.Borders.Right = New prt.LineDef("0mm", Color.white)
rt.Cells(1,3).text ="制单人:" & tbl.current("姓名")  \'通过左边空格数量来调整副标题位置
rt.Cells(1,3).Spancols = 3 \'合并第二行全部单元格,用于显示副标题
rt.Cells(1,3).Style.Borders.Right = New prt.LineDef("0mm", Color.white)
rt.Cells(1,6).text ="日期:" & tbl.current("日期")  \'通过左边空格数量来调整副标题位置
rt.Cells(1,6).Spancols = 4 \'合并第二行全部单元格,用于显示副标题
rt.Cells(1,6).Style.Borders.Right = New prt.LineDef("0mm", Color.white)
rt.Cells(2,0).text = "供应商:[" & tbl.Current("供应商") & "]" & tbl.Current("供应商名称")  \'通过左边空格数量来调整副标题位置
rt.Cells(2,0).Spancols = 3 \'合并第二行全部单元格,用于显示副标题
rt.Cells(2,0).Style.Borders.Right = New prt.LineDef("0mm", Color.white)
rt.Cells(2,3).text ="仓位:" & tbl.current("门店")  \'通过左边空格数量来调整副标题位置
rt.Cells(2,3).Spancols = 3 \'合并第二行全部单元格,用于显示副标题
rt.Cells(2,3).Style.Borders.Right = New prt.LineDef("0mm", Color.white)
rt.Cells(2,6).text ="自营定货单号:" & tbl.current("验收")  \'通过左边空格数量来调整副标题位置
rt.Cells(2,6).Spancols = 4 \'合并第二行全部单元格,用于显示副标题
rt.Cells(2,6).Style.Borders.Right = New prt.LineDef("0mm", Color.white)
rt.Cells(3,0).text = "备注:" \'通过左边空格数量来调整副标题位置
rt.Cells(3,0).Spancols = 7
rt.Cells(3,0).Style.Borders.Right = New prt.LineDef("0mm", Color.white)

rt.Cells(3,7).Spancols = 3
rt.Cells(3,7).Style.Borders.Right = New prt.LineDef("0mm", Color.white)
rt.Rows(0).Style.Borders.All = New prt.LineDef("0mm", Color.white) \'去掉第一行的网格线
rt.Rows(1).Style.Borders.All = New prt.LineDef("0mm", Color.white)\'去掉第二行的网格线
rt.Rows(2).Style.Borders.All = New prt.LineDef("0mm", Color.white)\'去掉第二行的网格线
rt.Rows(3).Style.Borders.All = New prt.LineDef("0mm", Color.white)\'去掉第二行的网格线
rt.Rows(3).Style.Borders.Bottom = New prt.Linedef  \'恢复第二行底端的网格线
rt.Rows(3).Height = 8  \'设置第二行的高度,拉开和表格主体的距离.
rt.RowGroups(0,1).Style.TextAlignVert = prt.AlignVertEnum.Center \'第一行内容垂直居中
rt.RowGroups(0,5).Header = prt.TableHeaderEnum.All \'将第一行作为表头.
rt.RowGroups(5,1).DataBinding.DataSource = BindTables("主表.明细表") \'将第二行绑定到订单表


Dim ColNames As String() = New String(){"行号","商品代码","条码","商品名称", "含量","单位", "进价","数量","件数","金额"}
For c As Integer = 0 To Colnames.Length -1
    rt.Cells(4,c).Text = ColNames(c)
    rt.Cols(c).Width = tb.Cols(ColNames(c)).PrintWidth
    rt.Cells(5, c).Text = "[Fields!" & ColNames(c) & ".Value]" \'设置绑定表达式
Next

rt.cells(rt.Rows.count-0,0).text= "金额合计:" 

rt.cells(rt.Rows.count-1,7).text= "总数" \'tbl.Current("数量")
rt.cells(rt.Rows.count-1,8).text= "总件数" \'tbl.Current("件数")
rt.cells(rt.Rows.count-1,9).text= tbl.Current("金额")


rt.cells(rt.Rows.count-0,1).text= "金额合计:" &  CUMoney(tbl.Current("金额")) & "元整"
rt.cells(rt.Rows.count-0,1).SpanCols= 7

rt.cells(rt.Rows.count-0,1).Style.TextAlignHorz = prt.AlignHorzEnum.Left

doc.Body.Children.Add(rt)
Doc.Preview

这个只能打印选中的一条数据,想设置为选多少打多少,换页后不打印表头和副标题,但需要显示页号固定在表格右上角,最后一行显示明细汇总的数量,件数,合计金额,页尾显示大写金额 不带边框,最后页脚 加上 经理: 验货: 制单人: 等留空签字 ,做了好久做不了.


--  作者:有点蓝
--  发布时间:2021/4/21 17:38:00
--  
只显示一次标题,去掉这句:rt.RowGroups(0,5).Header = prt.TableHeaderEnum.All \'将第一行作为表头.

把最后一会的表格边框设置为白色:http://www.foxtable.com/webhelp/topics/1200.htm

或者最后一行的内容不要放到表格里,直接使用RenderText添加内容

--  作者:lds
--  发布时间:2021/4/21 18:03:00
--  

可是第二页不显示列名了,还有怎么不让他自动换行,就是固定行高呢? rt.cells(rt.Rows.count-1,7).text= "总数" \'tbl.Current("数量") 我怎么sum明细表("数量")呢?

--  作者:有点蓝
--  发布时间:2021/4/22 8:23:00
--  
1、
rt.RowGroups(0,5).Header = prt.TableHeaderEnum.All 
改为
rt.RowGroups(4,1).Header = prt.TableHeaderEnum.All 


--  作者:lds
--  发布时间:2021/4/22 10:38:00
--  
rt.Cells(2,0).text = "供应商: [ " & tbl.Current("供应商") & "] " & tbl.Current("供应商名称")  \' 怎样才能 输出 一对  [ ]  方括号
--  作者:有点蓝
--  发布时间:2021/4/22 10:49:00
--  
上面的代码就是
--  作者:lds
--  发布时间:2021/4/22 11:42:00
--  
rt.Cells(2,0).text = "供应商: [ " & tbl.Current("供应商") & "] " & tbl.Current("供应商名称")  \'

加一个可以,加一对就都不显示了



--  作者:有点蓝
--  发布时间:2021/4/22 12:22:00
--  
是不是内容太多超出了单元格显示大小?
--  作者:lds
--  发布时间:2021/4/22 13:09:00
--  
  不是 rt.Cells(2,0).text = "供应商: { " & tbl.Current("供应商") & "}" & tbl.Current("供应商名称")  没有问题,
rt.Cells(2,0).text = "供应商: " & tbl.Current("供应商") & "]" & tbl.Current("供应商名称")  \'会有一个中括号   ,
是不是报表里面成对的[] 是默认为是 列名  就把[] 给去掉了.

--  作者:有点蓝
--  发布时间:2021/4/22 14:00:00
--  
是有这种问题,我反馈一下