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 '设置下边距
doc.Preview()
此主题相关图片如下:888.png