以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 水平转垂直表,多层表头,合计求助 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=148468) |
-- 作者:dxjwlf -- 发布时间:2020/4/8 15:52:00 -- 水平转垂直表,多层表头,合计求助 Dim dtb As New DataTableBuilder("统计") dtb.AddDef("客户", Gettype(String), 16) dtb.AddDef("编号", Gettype(String), 16) Dim prds As List(Of String()) prds = DataTables("订单明细").GetValues("产品名称|规格") For Each prd As String() In prds dtb.AddDef(prd(0)& "_" & prd(1), Gettype(String), 16) Next dtb.Build() For Each cus As String() In DataTables("订单表").GetValues("客户名称|客户编号") Dim dr As DataRow = DataTables("统计").AddNew() dr("客户") = cus(0) dr("编号") = cus(1) For Each prd As String() In prds dr(prd(0)& "_" & prd(1))= DataTables("订单明细").Compute("Sum(数量)","客户编号 = \'" & cus(1) & "\' And [产品名称] = \'" & prd(0) & "\' And [规格] = \'" & prd(1) & "\'") Next Next MainTable= Tables("统计") Dim doc As New PrintDoc \'定义一个新报表 Dim rt As New prt.RenderTable \'定义一个新表格 Dim rs As New prt.RenderText Dim tb As Table = Tables("统计") Dim hd As Integer = tb.HeaderRows \'获得表头的层数 rt.Style.Font = New Font("宋体",11) \'设置字体 rt.Style.Gridlines.All = New prt.Linedef(Color.Gray) \'灰色网格线 rt.CellStyle.Spacing.All = 0.8 \'单元格内距设为0.5毫米 rt.RowGroups(0, tb.HeaderRows).Header = prt.TableHeaderEnum.All \'利用行组功能设置表头 tb.CreateReportHeader(rt,False) \'生成表头,包括所有列 For c As Integer = 0 To tb.Cols.Count -1 \'逐列设置和填入内容 For r As Integer = 0 To tb.Rows.Count -1 \'开始填入该列内容 rt.Cells(r + hd , c).Text = tb(r,c) Next Next For ii As Integer= 2 To tb.Cols.Count -1 For Each Prd As String() In Prds rt.Cells(tb.rows.Count+2 ,ii).Text = DataTables("订单明细").Compute("Sum(数量)", "[产品名称] = \'" & prd(0) & "\' And [规格] = \'" & prd(1) & "\'") Next Next doc.Body.Children.Add(rt) \'将表格加入到报表 \'doc.PageSetting.Landscape = True \'横向打印 Doc.PageSetting.LeftMargin = 10 \'设置左边距 Doc.PageSetting.RightMargin = 10 \'设置右边距 Doc.PageSetting.TopMargin = 10 \'设置上边距 Doc.PageSetting.BottomMargin = 10 \'设置下边距
|
-- 作者:有点蓝 -- 发布时间:2020/4/8 17:10:00 -- For ii As Integer= 2 To tb.Cols.Count -1 dim ar() as string = tb.Cols(ii).name.split("_") rt.Cells(tb.rows.Count+2 ,ii).Text = DataTables("订单明细").Compute("Sum(数量)", "[产品名称] = \'" & ar(0) & "\' And [规格] = \'" & ar(1) & "\'") Next
|
-- 作者:dxjwlf -- 发布时间:2020/4/8 22:44:00 -- 追问: 新问题 因为使用了MainTable= Tables("统计") ,我的主界面使用了模式窗口,窗口中加入窗口的方式 建立 框架,导至打印时 子窗口(绑定的是主表)丢失。如果用build(true)又要求使用datatable,打印代码又不能改动。纠结 |
-- 作者:有点蓝 -- 发布时间:2020/4/9 9:21:00 -- 去掉MainTable= Tables("统计") ,对1楼的代码没有任何影响。 |