'环境判断
If Forms("日记账").Opened Then
Else
MessageBox.Show("【日记账】窗口未打开!", "提示")
Return ""
End If
If Tables("日记账_Table1").Rows.Count > 0 Then
Else
MessageBox.Show("【日记账】无有效数据!", "提示")
Return ""
End If
'页面设置
Dim doc As New PrintDoc
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 '设置下边距
'定义变量
Dim tbl As Table = Tables("日记账_Table1")
Dim s1 As String = tbl.Rows(0)("会计科目_全名")
Dim text As String = s1.Remove(s1.IndexOf("_"))
Dim text2 As String = "科目:" & tbl.Rows(0)("会计科目_代码") & "/" & s1.SubString(s1.IndexOf("_") + 1)
Dim ys As List(Of String) = tbl.DataTable.GetValues("日期_年", tbl.Filter, "排序")
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(Color.Gray) '灰色网格线
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, 6).Text = "单位:元" '第二行设置文本对象的内容
rt.Cells(2, 0).Text = "日期"
rt.Cells(2, 1).Text = "凭证字"
rt.Cells(2, 2).Text = "凭证编号"
rt.Cells(2, 3).Text = "摘要"
rt.Cells(2, 4).Text = "本期发生额"
rt.Cells(3, 4).Text = "借方"
rt.Cells(3, 5).Text = "贷方"
rt.Cells(2, 6).Text = "余额"
rt.Cells(2, 7).Text = "核对勾选"
'合并表头
rt.Cells(0, 0).SpanCols = 8 '第1行第1个单元格向右合并8列 (标题)
rt.Cells(1, 0).SpanCols = 6 '第2行第1个单元格向右合并6列 (标题)
rt.Cells(1, 6).SpanCols = 2 '第2行第1个单元格向右合并2列 (单位)
rt.Cells(2, 0).SpanRows = 2 '第3行第1个单元格向下合并2行 (日期)
rt.Cells(2, 1).SpanRows = 2 '第3行第2个单元格向下合并2行 (凭证字)
rt.Cells(2, 2).SpanRows = 2 '第3行第3个单元格向下合并2行 (凭证编号)
rt.Cells(2, 3).SpanRows = 2 '第3行第4个单元格向下合并2行 (摘要)
rt.Cells(2, 4).SpanCols = 2 '第3行第5个单元格向右合并2列 (本期发生额)
rt.Cells(2, 6).SpanRows = 2 '第3行第7个单元格向下合并2行 (余额)
rt.Cells(2, 7).SpanRows = 2 '第3行第8个单元格向下合并2行 (核对勾选)
'设置列宽
rt.Cols(0).Width = 55
rt.Cols(1).Width = 30
rt.Cols(2).Width = 80
rt.Cols(3).Width = 205
rt.Cols(4).Width = 70
rt.Cols(5).Width = 70
rt.Cols(6).Width = 70
rt.Cols(7).Width = 25
'设置样式
rt.Style.TextAlignHorz = prt.AlignHorzEnum.Center '内容水平居中
rt.Style.TextAlignVert = prt.AlignVertEnum.Center '内容垂直居中
rt.RowGroups(0, 5).Header = prt.TableHeaderEnum.All '将前四行作为表头.
rt.ColGroups(0, 1).Header = prt.TableHeaderEnum.All '将第一列作为分组列.
rt.Rows(0).Height = 10 '标题行高
rt.Rows(0).Style.Font = New Font("宋体", 16, FontStyle.Bold) '设置文本对象的字体
rt.Rows(1)(0).Style.Font = New Font("宋体", 11, FontStyle.Bold) '设置文本对象的字体
rt.Rows(1)(6).Style.Font = New Font("宋体", 9, FontStyle.Bold) '设置文本对象的字体
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)(6).Style.Borders.Left = New prt.LineDef("0mm", Color.white) '去掉第二行最后单元格的网格线
rt.Rows(1).Style.Borders.Bottom = New prt.Linedef(Color.Gray) '恢复第二行底端的网格线
rt.Rows(0).Style.TextAlignHorz = prt.AlignHorzEnum.Center '第一行内容水平居中
rt.Rows(1)(0).Style.TextAlignHorz = prt.AlignHorzEnum.Left '第二行第一列内容靠左
rt.Rows(1)(6).Style.TextAlignHorz = prt.AlignHorzEnum.Center '第二行第最后列内容居中
rt.Rows(2).Style.Font = New Font("宋体", 10, FontStyle.Bold) '设置文本对象的字体
rt.Rows(3).Style.Font = New Font("宋体", 10, FontStyle.Bold) '设置文本对象的字体
'表格细节赋值
For Each y As String In ys '分年打印
pds = tbl.DataTable.GetValues("日期_月", "日期_年 = '" & y & "'", "排序")
For Each pd As String In pds '分月打印
If tbl.Filter > "" Then
drs = tbl.DataTable.Select("日期_年 = '" & y & "' And 日期_月 = '" & pd & "' And " & tbl.Filter, "排序")
Else
drs = tbl.DataTable.Select("日期_年 = '" & y & "' And 日期_月 = '" & pd & "'", "排序")
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
rt.Cells(cnt, c).Text = ""
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
'格式化数据
If rt.Cells(cnt, 7).Text = "True" Then
rt.Cells(cnt, 7).Text = "√"
Else
rt.Cells(cnt, 7).Text = "×"
End If
'调整对齐
rt.Cells(cnt, 0).Style.TextAlignHorz = prt.AlignHorzEnum.Left '数据水平靠右
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 '数据水平靠右
Next
Next
cnt = rt.Rows.Count
rt.Cells(cnt, 0).Text = pd & "月小计 " '打印月小计
rt.Cells(cnt, 0).SpanCols = 4 '月小计行第1个单元格向右合并4行 (月小计行)
rt.Rows(cnt).Style.BackColor = Color.WhiteSmoke '小计行背景颜色设为白烟色.
rt.Cells(cnt, 4).Text = Format(tbl.compute("Sum(本期发生额_借方)", "日期_年 = '" & y & "' And 日期_月 = '" & pd & "'"), "#,##0.00")
rt.Cells(cnt, 5).Text = Format(tbl.compute("Sum(本期发生额_贷方)", "日期_年 = '" & y & "' And 日期_月 = '" & pd & "'"), "#,##0.00")
rt.Cells(cnt, 4).Style.TextAlignHorz = prt.AlignHorzEnum.Right '数据水平靠右
rt.Cells(cnt, 5).Style.TextAlignHorz = prt.AlignHorzEnum.Right '数据水平靠右
Next
cnt = rt.Rows.Count
rt.Cells(cnt, 0).Text = y & "年累计 " '打印月小计
rt.Cells(cnt, 0).SpanCols = 4 '月小计行第1个单元格向右合并4行 (月小计行)
rt.Rows(cnt).Style.BackColor = Color.WhiteSmoke '小计行背景颜色设为白烟色.
rt.Cells(cnt, 4).Text = Format(tbl.compute("Sum(本期发生额_借方)", "日期_年 = '" & y & "'"), "#,##0.00")
rt.Cells(cnt, 5).Text = Format(tbl.compute("Sum(本期发生额_贷方)", "日期_年 = '" & y & "'"), "#,##0.00")
rt.Cells(cnt, 4).Style.TextAlignHorz = prt.AlignHorzEnum.Right '数据水平靠右
rt.Cells(cnt, 5).Style.TextAlignHorz = prt.AlignHorzEnum.Right '数据水平靠右
rt.Rows(cnt).Style.Font = New Font("宋体", 10, FontStyle.Bold) '设置文本对象的字体加粗
Next
'最后一页最后行增加总计行
rt.Rows.Count = rt.Rows.Count + 1
rt.Rows(rt.Rows.count - 1)(0).text = "总计"
rt.Rows(rt.Rows.count - 1)(0).SpanCols = 4 '总计行第1个单元格向右合并4行 (总计行)
rt.Rows(rt.Rows.count - 1).Style.BackColor = Color.LightGray '总计行背景颜色设为灰色.
rt.Rows(rt.Rows.count - 1)(4).text = Format(tbl.compute("Sum(本期发生额_借方)"), "#,##0.00")
rt.Rows(rt.Rows.count - 1)(5).text = Format(tbl.compute("Sum(本期发生额_贷方)"), "#,##0.00")
rt.Rows(rt.Rows.count - 1)(4).Style.TextAlignHorz = prt.AlignHorzEnum.Right '数据水平靠右
rt.Rows(rt.Rows.count - 1)(5).Style.TextAlignHorz = prt.AlignHorzEnum.Right '数据水平靠右
'添加页脚
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.Bottom = 0.2 '底端内容缩进0.2毫米
rx.Style.FontSize = 9 '字体大小为9磅
Doc.PageFooter = rx '作为页脚使用
doc.Body.Children.Add(rt) '将表格加入到报表
doc.Preview() '打印