'环境判断
If Forms("应收账款明细账").Opened Then
Else
MessageBox.Show("【应收账款明细账】窗口未打开!", "提示")
Return ""
End If
If Tables("应收账款明细账").Rows.Count > 0 Then
Else
MessageBox.Show("【应收账款明细账】无有效数据!", "提示")
Return ""
End If
Dim fz As DataTable = DataTables ("应收账款明细账_辅助表")
Dim doc As New PrintDoc '定义一个报表
For i As Integer = 0 To fz.DataRows.Count - 1
Rsn = 0
Functions.Execute("应收账款明细分类账加载(打印用)")
'页面设置
Dim cr As Color '定义网格线颜色
Dim ht As Integer '定义行高
Dim Fzt01 As Font '定义标题1字体
Dim Fzt02 As Font '定义标题2字体
Dim Fzt03 As Font '定义正文字体
Dim Fzt04 As Font '定义页眉字体
Dim Fzt05 As Font '定义页脚字体
Dim Fzt06 As Font '定义页脚字体
doc.PageSetting.PaperKind = 9 '纸张类型改为A4
doc.PageSetting.Landscape = True '横向打印
doc.PageSetting.LeftMargin = 30 '设置左边距
doc.PageSetting.RightMargin = 30 '设置右边距
doc.PageSetting.TopMargin = 20 '设置上边距
doc.PageSetting.BottomMargin = 20 '设置下边距
cr = Color.Gray
ht = 6
Fzt01 = New Font("宋体", 16, FontStyle.Bold)
Fzt02 = New Font("宋体", 11, FontStyle.Bold)
Fzt03 = New Font("宋体", 10, FontStyle.Regular)
Fzt04 = New Font("宋体", 9, FontStyle.Regular)
Fzt05 = New Font("宋体", 9, FontStyle.Regular)
Fzt06 = New Font("宋体", 10, FontStyle.Bold)
'定义变量
Dim tbl As Table = Tables("应收账款明细账_打印用")
Dim text As String = "应收账款明细账"
Dim text2 As String
Dim text3 As String
If fz.DataRows.Count > 0 Then
Dim fzdr As DataRow = fz.DataRows (Rsn) '定位行
Dim s1 As String = CStr(fzdr("日期起")) '将变量日期起的内容转换为字符串
Dim s2 As String = CStr(fzdr("日期至")) '将变量日期至的内容转换为字符串
Dim s11 As String = s1.Replace("-", "").Trim()
Dim s21 As String = s2.Replace("-", "").Trim()
text2 = "客户:" & fzdr ("客户编号") & "/" & fzdr ("客户名称")
text3 = "日期:" & s11 & "至" & s21
Else
text2 = "客户:"
text3 = "日期:"
End If
Dim pds As List(Of String)
Dim drs As List(Of DataRow)
Dim cnt As Integer
Dim dwmc As String
Dim pzdr As DataRow = DataTables("系统配置").Find("编号 = 'XTPZ-001'")
If pzdr IsNot Nothing Then
dwmc = pzdr("单位名称")
End If
'定义表格
Dim rt As New prt.RenderTable '定义一个新表格
rt.Style.Gridlines.All = New prt.Linedef(cr) '灰色网格线
'rt.Style.Gridlines.Left = New prt.LineDef("0mm", Color.white) '去掉左边框的网格线
'rt.Style.Gridlines.Right = New prt.LineDef("0mm", Color.white) '去掉右边框的网格线
rt.CellStyle.Spacing.All = 1 '内容距离网格线1毫米
'定义表头
rt.Cells(0, 0).Text = text '第一行设置文本对象的内容
rt.Cells(1, 0).Text = text2 '第二行设置文本对象的内容
rt.Cells(1, 2).Text = text3 '第二行设置文本对象的内容
rt.Cells(1, 5).Text = "单位:元" '第二行设置文本对象的内容
rt.Cells(2, 0).Text = "日期"
rt.Cells(2, 1).Text = "摘要"
rt.Cells(2, 2).Text = "单据编号"
rt.Cells(2, 3).Text = "本期发生额"
rt.Cells(3, 3).Text = "借方"
rt.Cells(3, 4).Text = "贷方"
rt.Cells(2, 5).Text = "期末余额"
'表头合并列
rt.Cells(0, 0).SpanCols = 6 '第1行第1个单元格向右合并6列 (标题)
rt.Cells(1, 0).SpanCols = 2 '第2行第1个单元格向右合并3列 (标题客户名称)
rt.Cells(1, 2).SpanCols = 3 '第2行第1个单元格向右合并2列 (标题日期)
rt.Cells(2, 0).SpanRows = 2 '第3行第1个单元格向下合并2行 (日期)
rt.Cells(2, 1).SpanRows = 2 '第3行第1个单元格向下合并2行 (摘要)
rt.Cells(2, 2).SpanRows = 2 '第3行第2个单元格向下合并2行 (单据编号)
rt.Cells(2, 3).SpanCols = 2 '第3行第4个单元格向右合并2行 (本期发生额)
rt.Cells(2, 5).SpanRows = 2 '第3行第5个单元格向下合并2列 (期末余额)
'设置列宽
'rt.Width = "Auto"
'rt.Cols(0).Width = 20
'rt.Cols(1).Width = 107
'rt.Cols(2).Width = 30
'rt.Cols(3).Width = 30
'rt.Cols(4).Width = 30
'rt.Cols(5).Width = 30
Dim cnr As Integer '用于记录列位置
For c As Integer = 0 To tbl.Cols.Count - 1 '逐列设置和填入内容
If tbl.Cols(c).Visible Then
rt.Cols(cnr).Width = tbl.Cols(c).PrintWidth '列宽等于实际列宽
cnr = cnr + 1
End If
Next
'定义样式
rt.Style.TextAlignHorz = prt.AlignHorzEnum.Center '内容水平居中
rt.Style.TextAlignVert = prt.AlignVertEnum.Center '内容垂直居中
rt.RowGroups(0, 4).Header = prt.TableHeaderEnum.All '将前四行作为表头.
rt.ColGroups(0, 1).Header = prt.TableHeaderEnum.All '将第一列作为分组列.
rt.Rows(0).Height = 10 '标题行高
rt.Rows(0).Style.Font = Fzt01 '设置文本对象的字体
rt.Rows(1)(0).Style.Font = Fzt02 '设置文本对象的字体
rt.Rows(1)(2).Style.Font = Fzt02 '设置文本对象的字体
rt.Cells(1, 2).Style.TextAlignHorz = prt.AlignHorzEnum.Left '靠左
rt.Rows(1)(5).Style.Font = Fzt05 '设置文本对象的字体
rt.Rows(0).Style.Borders.All = New prt.LineDef("0mm", Color.white) '去掉第一行的网格线
rt.Rows(1).Style.Borders.All = New prt.LineDef("0mm", Color.white) '去掉第二行的网格线
rt.Rows(1)(2).Style.Borders.Left = New prt.LineDef("0mm", Color.white) '去掉第二行第3单元格的网格线
rt.Rows(1)(5).Style.Borders.Left = New prt.LineDef("0mm", Color.white) '去掉第二行最后单元格的网格线
rt.Rows(1).Style.Borders.Bottom = New prt.Linedef(cr) '恢复第二行底端的网格线
rt.Rows(0).Style.TextAlignHorz = prt.AlignHorzEnum.Center '第一行内容水平居中
rt.Rows(1)(0).Style.TextAlignHorz = prt.AlignHorzEnum.Left '第二行第一列内容靠左
rt.Rows(1)(5).Style.TextAlignHorz = prt.AlignHorzEnum.Center '第二行第最后列内容居中
rt.Rows(2).Style.Font = Fzt02 '设置文本对象的字体
rt.Rows(3).Style.Font = Fzt02 '设置文本对象的字体
rt.Rows(2).Height = ht '设置行高
rt.Rows(3).Height = ht '设置行高
'判断是否筛选
If tbl.Filter > "" Then
drs = tbl.DataTable.Select(tbl.Filter, "排序")
Else
drs = tbl.DataTable.Select("", "排序")
End If
'表格细节区赋值
For Each dr As DataRow In drs
cnt = rt.Rows.Count
For c As Integer = 0 To tbl.Cols.Count - 1
If tbl.Cols(c).Name = "发生额_借方" OrElse tbl.Cols(c).Name = "发生额_贷方" OrElse tbl.Cols(c).Name = "余额" Then
If dr(tbl.Cols(c).Name) = 0 Then
If dr(tbl.Cols(1).Name) = "期初余额" Then
If tbl.Cols(c).Name = "余额" Then
rt.Cells(cnt, c).Text = Format(dr(tbl.Cols(c).Name), "#,##0.00") '格式化数字后赋值
Else
rt.Cells(cnt, c).Text = ""
End If
Else
rt.Cells(cnt, c).Text = ""
End If
Else
rt.Cells(cnt, c).Text = Format(dr(tbl.Cols(c).Name), "#,##0.00") '格式化数字后赋值
End If
Else
rt.Cells(cnt, c).Text = dr(tbl.Cols(c).Name) '其余逐行赋值
End If
'调整对齐
rt.Cells(cnt, 0).Style.TextAlignHorz = prt.AlignHorzEnum.Left '数据水平靠左
rt.Cells(cnt, 1).Style.TextAlignHorz = prt.AlignHorzEnum.Left '数据水平靠左
rt.Cells(cnt, 2).Style.TextAlignHorz = prt.AlignHorzEnum.Left '数据水平靠左
rt.Cells(cnt, 3).Style.TextAlignHorz = prt.AlignHorzEnum.Right '数据水平靠右
rt.Cells(cnt, 4).Style.TextAlignHorz = prt.AlignHorzEnum.Right '数据水平靠右
rt.Cells(cnt, 5).Style.TextAlignHorz = prt.AlignHorzEnum.Right '数据水平靠右
rt.Cells(cnt, 6).Style.TextAlignHorz = prt.AlignHorzEnum.Right '数据水平靠右
rt.Rows(cnt).Height = ht '设置行高
rt.Rows(cnt).Style.Font = Fzt03 '设置文本对象的字体
Next
Next
'最后一页最后行增加合计
rt.Rows.Count = rt.Rows.Count + 1
rt.Rows(rt.Rows.count - 1)(0).text = "总计"
rt.Rows(rt.Rows.count - 1)(0).SpanCols = 2 '总计行第1个单元格向右合并4行 (总计行)
rt.Rows(rt.Rows.count - 1).Style.BackColor = Color.LightGray '总计行背景颜色设为灰色.
rt.Rows(rt.Rows.count - 1)(3).text = Format(tbl.compute("Sum(发生额_借方)"), "#,##0.00")
rt.Rows(rt.Rows.count - 1)(4).text = Format(tbl.compute("Sum(发生额_贷方)"), "#,##0.00")
rt.Rows(rt.Rows.count - 1)(2).Style.TextAlignHorz = prt.AlignHorzEnum.Right '数据水平靠右
rt.Rows(rt.Rows.count - 1)(3).Style.TextAlignHorz = prt.AlignHorzEnum.Right '数据水平靠右
rt.Rows(rt.Rows.count - 1)(4).Style.TextAlignHorz = prt.AlignHorzEnum.Right '数据水平靠右
rt.Rows(rt.Rows.count - 1)(5).Style.TextAlignHorz = prt.AlignHorzEnum.Right '数据水平靠右
rt.Rows(rt.Rows.count - 1).Height = ht '设置行高
rt.Rows(rt.Rows.count - 1).Style.Font = Fzt06 '设置文本对象的字体
'添加页脚
Dim rx As New prt.RenderTable
rx.Cells(0, 0).Text = "账套:" & dwmc
rx.Cells(0, 1).Text = RJ
rx.Cells(0, 2).Text = "操作:" & _UserName
rx.Cells(0, 3).Text = "打印:" & Format(Date.Now, "yyyy-MM-dd HH:mm:ss")
rx.Cells(0, 4).Text = "第[PageNo]页,共[PageCount]页"
rx.Cols(0).Style.TextAlignHorz = prt.AlignHorzEnum.Left '各列对齐
rx.Cols(1).Style.TextAlignHorz = prt.AlignHorzEnum.Center
rx.Cols(2).Style.TextAlignHorz = prt.AlignHorzEnum.Center
rx.Cols(3).Style.TextAlignHorz = prt.AlignHorzEnum.Center
rx.Cols(4).Style.TextAlignHorz = prt.AlignHorzEnum.right
rx.Style.Borders.Top = New prt.LineDef '设置上边框
rx.CellStyle.Spacing.top = 1 '上部距离1毫米
rx.Style.Font = Fzt05 '字体
Doc.PageFooter = rx '作为页脚使用
doc.Body.Children.Add(rt) '将表格加入到报表
rt.BreakAfter = prt.BreakEnum.Page '强制分页
Rsn = Rsn + 1
Next
doc.Preview() '打印
计划根据RSN变量顺序加载顺序打印,现在效果如下:
此主题相关图片如下:微信截图_20220923072845.png
此主题相关图片如下:微信截图_20220923074149.png
出现问题:
1、第一个客户数据完整,后面客户无数据;
2、后面客户表头数据也为空。
我是左右没有办法了,麻烦老师帮忙修改一下,谢谢!