辛苦老师了 终于实现了目标 还有个小功能需要实现 麻烦老师
Dim tbl As Table = Tables("订单_产品主表")
Dim Rows As List(Of DataRow)
Dim Regions As List(Of String) = tbl.DataTable.GetValues("区域名称")
doc.Pagesetting.LandScape = True
Dim ColNames As String() = New String() {"区域名称", "产品名称", "工艺描述", "销售单价", "计价单位", "数量", "金额小计", "备注" }
For Each Region As String In Regions
rx = New prt.RenderText
rx.Style.Font = New Font("宋体", 12) '设置字体
rx.Style.Spacing.Bottom = 1
rx.Text = "区域: " & Region
doc.Body.Children.Add(rx)
For Each dr2 As DataRow In tbl.DataTable.Select("区域名称='" & Region & "'")
rt = New prt.RenderTable
rt.Style.Font = tbl.Font
rt.Style.TextAlignVert = prt.AlignVertEnum.Center
rt.Style.GridLines.All = New prt.LineDef(0.3, Color.DeepSkyBlue)
rt.Style.Spacing.Bottom = 2
rt.CellStyle.Spacing.All = 1
For c As Integer = 0 To ColNames.Length - 1 '逐列设置和填入内容
rt.Cells(0, c).Text = ColNames(c) '列名作为标题
rt.Cells(0, c).Style.TextAlignHorz = prt.AlignHorzEnum.Center '标题内容水平居中
If ColNames(c) <> "备注" Then '
rt.Cols(c).Width = tbl.Cols(ColNames(c)).PrintWidth
End If
rt.Cells(1, c).Text = dr2(ColNames(c))
rt.Cells(1, c).Style.BackColor = Color.DarkGray '产品表头颜色
rt.Cells(1, c).Style.Font = New Font("宋体", 11) '设置字体
Next
Dim cnt As Integer '流水号
Rows = DataTables("订单_产品清单").sqlSelect("[产品订购ID] = '" & dr2("产品订购ID") & "'")
For r As Integer = 0 To Rows.Count - 1 '开始填入该列内容
cnt = cnt + 1
rt.Cells(r + 2, 0).Text = cnt
此主题相关图片如下:企业微信截图_20220425225321.png
For c As Integer = 1 To ColNames.Length - 1
rt.Cells(r + 2, c).Text = Rows(r)(ColNames(c))
rt.Cells(r + 2, c).Style.Font = New Font("宋体", 9) '设置字体
Next
Next
rt.Style.GridLines.All = New prt.Linedef '设置网格线
rt.Cols(0).Width = 15 '设置前四列的宽度,剩余的宽度被分配给5列(显示图片的那列)
rt.Cols(1).Width = 35
rt.Cols(2).Width = 30
rt.Cols(3).Width = 50
rt.Cols(4).Width = 20
rt.Cols(5).Width = 20
rt.Cols(6).Width = 10
rt.Cols(7).Width = 30
rt.CellStyle.Spacing.All = 0.3 '内容距离网格线0.5毫米
rt.Style.Font = New Font("宋体", 11) '设置字体
rt.Style.TextAlignHorz = prt.AlignHorzEnum.Center '第一行内容水平居中
rt.Style.TextAlignVert = prt.AlignVertEnum.Center '第一行内容垂直居中
rt.Rows(0).Style.BackColor = Color.DimGray '第一行背景颜色设为灰色.
rt.RowGroups(0, 1).Header = prt.TableHeaderEnum.All '将第一行作为表头..
doc.Body.Children.Add(rt) '将表格加入到报表
Next
Next