Dim doc As New PrintDoc
Dim rt As New prt.RenderTable
Dim rx As New prt.RenderText '定义一个文本对象
rt.Width = "Auto"
'表格宽度为自动,也就是等于各列设置宽度之和
Doc.PageSetting.LeftMargin
= 8 '设置左边距
Doc.PageSetting.RightMargin
= 5 '设置右边距
Doc.PageSetting.TopMargin
= 10 '设置上边距
Doc.PageSetting.BottomMargin
= 10 '设置下边距
rx.text = "未满箱明细"
rx.Style.FontBold = True '字体加粗
rx.Style.FontSize = 16 '大体大小为16磅
rx.Style.TextAlignHorz
= prt.AlignHorzEnum.Center '水平居中排列
rx.Style.Spacing.Bottom = 3 '和下面的对象(表格)距离3毫米
doc.Body.Children.Add(rx) '加入到报表中
Dim tb As Table = Tables("未满箱明细_table1")
Dim ColNames As String() = New String(){"客人代码","款号","前幅","后幅","客人订单号","客人交期","数量","已完成数量"}
Dim MergeCols As Integer = 4 '指定要合并的列数
tb.Sort = "客人代码,款号,前幅,后幅,客人交期"
'根据合并列排序
rt.Width = "Auto"
rt.SplitHorzBehavior = prt.SplitBehaviorEnum.SplitIfNeeded
rt.Style.Font = tb.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
rt.Cols(c).Width = tb.Cols(ColNames(c)).PrintWidth
If tb.Cols(ColNames(c)).IsNumeric OrElse tb.Cols(ColNames(c)).IsDate Then
rt.Cols(c).Style.TextAlignHorz = prt.AlignHorzEnum.Right
End If
For r As Integer = 0 To tb.Rows.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 tb.Rows(r)(ColNames(n))
<> tb.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
Else
rt.Cells(r + 1, c).Text = tb.Rows(r)(ColNames(c))
Dim rw As Row = tb.Rows(r)
rt.Cells(r+1,2).Image = GetImage(rw("前幅"))
rt.Cells(r+1,3).Image = GetImage(rw("后幅"))
rt.Cells(r + 1, c).VertSplitBehavior
= prt.CellSplitBehaviorEnum.Copy '换页后重复单元格
lr
= r + 1
End
If
Else
rt.Cells(r + 1, c).Text = tb.Rows(r)(ColNames(c))
End If
Next
Next
rt.Style.Gridlines.All = New prt.Linedef(Color.Gray)
rt.CellStyle.Spacing.All = 0.5
rt.Rows(0).Style.TextAlignHorz
= prt.AlignHorzEnum.Center
rt.RowGroups(0,1).Header = prt.TableHeaderEnum.All
Dim drs As List(Of DataRow) '定义一个行集合
Dim cp As List(Of String) =
tb.DataTable.GetValues("款号",tb.Filter) '以集合形式,从指定列中获取并返回不重复的值
Dim kh As List(Of String) =
tb.DataTable.GetValues("客人代码",tb.Filter) '以集合形式,从指定列中获取并返回不重复的值
For p As Integer = 0 To math.Ceiling(tb.Rows.Count) -
1
Dim cnt As
Integer
rt.Width =
"Auto" '表格宽度为自动,也就是等于各列设置宽度之和
rt.SplitHorzBehavior
= prt.SplitBehaviorEnum.SplitIfNeeded '表格宽度超出页宽时,可以水平换页
rt.Style.GridLines.All = New prt.LineDef(0.3,Color.LightGray) '线宽0.3mm,深灰色网格线
rt.CellStyle.Spacing.All = 1 '单元格内距设为1毫米
rt.Style.Font = tb.Font '字体为数据表字体
For c As Integer
= 0 To tb.Cols.Count - 1 '生成列标题
rt.Cells(0,c).Text = tb.Cols(c).Name '用绑定表的列名作为表格列标题文本
rt.Cols(c).Width = tb.Cols(c).PrintWidth '数据表列宽为表格列宽
Next
cp =
tb.DataTable.GetValues("款号",tb.Filter) '返回产品不重复的值
For Each pd
As String In cp '分产品打印 msgbox(cp)
kh =
tb.DataTable.GetValues("客人代码",tb.Filter And
" 款号 = '" & pd &
"'")
For Each
pdd As String In kh '分客户打印
Dim Filter = ""
If tb.Filter > ""
Then
Filter = "款号 = '"
& pd & "' and 客人代码 = '"
& pdd & "' And "
& tb.Filter
Else
Filter = "款号 = '"
& pd & "' and 客人代码 = '"
& pdd & "'"
End If
dim c1 as
integer = rt.Rows.Count
For Each dr
As DataRow In drs '逐行打印此产品的订单
cnt = rt.Rows.Count
For c As Integer = 0 To tbl.Cols.Count - 1
rt.Cells(cnt, c).Text = dr(tbl.Cols(c).Name)
Next
Next
rt.Cells(c1,0).SpanRows = drs.count
cnt = rt.Rows.Count
rt.Cells(cnt, 0).Text = pdd & "合计 " '打印产品的小计
rt.Cells(cnt, 0).style.TextAlignHorz = prt.AlignHorzEnum.right '水平居中排列
rt.Cells(cnt, 0).Style.FontBold = True '字体加粗
rt.Cells(cnt, 0).Style.FontSize = 10.5 '大体大小为16磅
rt.Cells(cnt, 2).Style.FontBold = True '字体加粗
rt.Cells(cnt, 2).Style.FontSize = 10.5 '大体大小为16磅
rt.Cells(cnt, 3).Style.FontBold = True '字体加粗
rt.Cells(cnt, 3).Style.FontSize = 10.5 '大体大小为16磅
rt.Cells(cnt,0).SpanCols = 2 '第5行第2个单元格向右合并3列(用于显示地址)
rt.Cells(cnt,2).Text = tbl.compute("Sum(数量)", "客人代码 = '"
& pd & "'") & "个"
Next
Next
Next
Next
doc.Body.Children.Add(rt)
doc.preview()
此主题相关图片如下:微信图片_20220816110529.png