按客户/雇员/产品筛选,然后在命令窗口加入以下代码执行:
Dim doc As New PrintDoc
Dim rt As Prt.RenderTable
Dim rx As prt.RenderText
Dim tbl As Table = Tables("订单")
Dim Rows As List(Of DataRow)
Dim Datas As List(Of String) = tbl.DataTable.GetValues("客户",tbl.Filter)
doc.Pagesetting.LandScape = True
For Each Data As String In Datas
rx = New prt.RenderText
rx.Style.FontSize = 8
rx.Text = Data
rx.x = 117
rx.y = 28
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 = 2
rt.Style.Font = tbl.Font
If tbl.Filter = "" Then
Rows = tbl.DataTable.Select("[客户] = '" & Data & "'")
Else
Rows = tbl.DataTable.Select("[客户] = '" & Data & "' And (" & tbl.Filter & ")")
End If
Dim ColNames As String() = New String(){"单价", "折扣","数量","金额"}
For c As Integer = 0 To ColNames.Length - 1 '逐列设置和填入内容
rt.Width = "Auto"
For i As Integer = 0 To 3
rt.Cols(0).Width = 20 '设置列宽
rt.Cols(1).Width = 24 '设置列宽
rt.Cols(2).Width = 12 '设置列宽
rt.Cols(3).Width = 12 '设置列宽
Next
For r As Integer = 0 To Rows.Count -1
rt.Cells(r + 1, c).Text = Rows(r)(ColNames(c))
Next
Next
rt.RowGroups(0,1).Header = prt.TableHeaderEnum.All
doc.Body.Children.Add(rt)
Next
Doc.PageSetting.LeftMargin = 24 '设置左边距
'Doc.PageSetting.RightMargin = 10 '设置右边距
Doc.PageSetting.TopMargin = 62 '设置上边距
'Doc.PageSetting.BottomMargin = 10 '设置下边距
doc.PageSetting.Width = 210 '纸张宽度为100毫米
doc.PageSetting.Height = 140 '纸张高度为120毫米
doc.preview()
结果:
此主题相关图片如下:uuu.jpg
在我的实际运用中,需要添加3段打印文本,以下代码打印了客户文本:
rx = New prt.RenderText
rx.Style.FontSize = 8
rx.Text = Data
rx.x = 117
rx.y = 28
doc.Body.Children.Add(rx)
如果想打印雇员和产品文本,上面的代码如何改?
另说明实际运用中,只需按客户筛选,雇员和产品这两列内容都是相同的。