结果是乱的,老师帮忙看看
Dim tbl As Table = Tables("订单_产品清单")
Dim Rows As List(Of DataRow)
Dim Regions As List(Of String) = tbl.DataTable.GetValues("区域_名称")
For Each Region As String In Regions
rx = New prt.RenderText
rx.Style.FontSize = 12
rx.Style.FontBold = True
rx.Style.Spacing.Bottom = 2
rx.Text = "区域: " & Region & " 合计:¥ " & tbl.Compute("Sum(金额小计)","区域_名称 = '"& Region &"' ")
doc.Body.Children.Add(rx)
rt = New prt.RenderTable
rt.Style.Font = Tables("订单_产品清单").Font
rt.Style.TextAlignVert = prt.AlignVertEnum.Center
rt.Style.GridLines.All = New prt.LineDef(0.3,Color.LightGray)
rt.Style.Spacing.Bottom = 5
rt.CellStyle.Spacing.All = 1
rt.Style.Font = tbl.Font
Rows = tbl.DataTable.Select("[区域_名称] = '" & Region & "'") '分组列为
'Dim ColNames As String() = New String(){"区域 Region","产品名称 Product name","产品图片 Picture","型号 Coding","产品尺寸 Dimensions","售价 Selling Price","单位 Unit","数量 Quantity","金额小计 Subtotal","备注 Notes"}
Dim ColNames As String() = New String(){"区域_名称","产品名称","图片","产品_定型ID","规格","单价","单位","数量","金额小计","备注"}
Dim MergeCols As Integer = 2 '指定要合并的列数
tbl.Sort = "区域_名称,产品名称" '根据合并列排序
rt.Width = "Auto"
rt.SplitHorzBehavior = prt.SplitBehaviorEnum.SplitIfNeeded
rt.Style.Font = tbl.Font
rt.Style.TextAlignVert = prt.AlignVertEnum.Center
rt.RepeatGridLinesVert = True '换页后重复表格线
For c As Integer = 0 To ColNames.Length - 1 '逐列设置和填入内容
Dim lr As Integer ' 用于保存合并区域的起始行
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
Dim drs As List(Of DataRow)
drs = tbl.DataTable.Select("[区域_名称] = '" & Region & "'")
For r As Integer = 0 To drs.Count -1 '开始填入该列内容
If c <= MergeCols - 1 Then '如果是要合并的列
Dim Merge As Boolean = True
If r = 0 Then
Merge = False '第一行默认不合并
Else
For n As Integer = 0 To c
If tbl.Rows(r)(ColNames(n)) <> tbl.Rows(r - 1)(ColNames(n)) '判断和上一行单元格数据是否一样,一样的就合并
Merge = False
Exit For
End If
Next
End If
If Merge Then '如果需要合并
rt.Cells(lr,c).SpanRows = rt.Cells(lr,c).SpanRows + 1 '设置合并
End If
If ColNames(c) <>"产品图片 Picture"
rt.Cells(r + 1, c).Text = drs(r)(ColNames(c))
Else
Dim name As String = Vars("bdwj") & "家具\" & filesys.getname(tbl.Rows(r)("图片"))
If FileSys.FileExists(name) Then
Else
Network.DownloadFile(tbl.Rows(r)("图片"), name)
End If
rt.Cells(r + 1,2).Image = GetImage(name)
rt.Style.ImageAlign.AlignHorz = prt.ImageAlignHorzEnum.Center '居中显示
End If
End If
Next
Next
rt.Style.GridLines.All = New prt.Linedef '设置网格线
rt.Cols(0).Width = 15 '设置前四列的宽度,剩余的宽度被分配给5列(显示图片的那列)
rt.Cols(1).Width = 20
rt.Cols(2).Width = 25
rt.Cols(3).Width = 15
rt.Cols(4).Width = 25
rt.Cols(5).Width = 15
rt.Cols(6).Width = 15
rt.Cols(7).Width = 10
rt.Cols(8).Width = 18
rt.Cols(9).Width = 30
rt.CellStyle.Spacing.All = 0.1 '内容距离网格线0.5毫米
rt.Style.TextAlignHorz = prt.AlignHorzEnum.Center '第一行内容水平居中
rt.Style.TextAlignVert = prt.AlignVertEnum.Center '第一行内容垂直居中
'rt.Rows(0).Style.TextAlignHorz = prt.AlignHorzEnum.Center '第一行内容水平居中
'rt.Rows(0).Style.TextAlignVert = prt.AlignVertEnum.Center '第一行内容垂直居中
rt.Rows(0).Style.BackColor = Color.LightGray '第一行背景颜色设为灰色.
rt.RowGroups(0,1).Header = prt.TableHeaderEnum.All '将第一行作为表头..
doc.Body.Children.Add(rt) '将表格加入到报表
Next
此主题相关图片如下:企业微信截图_20220112172625.png

[此贴子已经被作者于2022/1/12 17:27:25编辑过]