-- 作者:yyzlxc
-- 发布时间:2011/11/14 12:59:00
-- [求助]专业报表如何添加分页小计和总计
一段专业报表代码,有一列为金额,能够生成专业报表,要求在此基础上添加每页金额小计和最后一页金额总计,代码应该如何修改,请各位老师帮助指教,谢谢!!
\'报表设计 Dim doc As New PrintDoc \'定义一个新报表 Dim rt As New prt.RenderTable \'定义一个新表格 Dim tb As Table = Tables( "yhzd" ) Dim ColNames As New List(Of String) For Each cl As Col In tb.Cols \'排除隐藏列 If cl.Visible Then ColNames.Add(cl.Name) End If Next \'设置表头 Dim rs As New prt.RenderText() \'定义一个文本对象 rt.Width = "Parent.Width" \'宽度等于容器宽度 rt.Style.Spacing.Top = 4 \'表格和前面对象的垂直间隔为4毫米 rs.Text = "银行账单" \'设置文本对象的内容 rs.Style.Font = New Font("宋体",14,FontStyle.Bold) \'设置文本对象的字体 rs.Style.TextAlignHorz = prt.AlignHorzEnum.Center \'文本内容水平居中 doc.Body.Children.Add(rs) \'将文本对象加入到表格中 doc.PageSetting.Landscape = False \'打印方向 doc.PageSetting.PaperKind = 9 \'设为A4纸 Doc.PageSetting.LeftMargin = 20 \'设置左边距 Doc.PageSetting.RightMargin = 20 \'设置右边距 Doc.PageSetting.TopMargin = 20 \'设置上边距 Doc.PageSetting.BottomMargin = 20 \'设置下边距 \'设置表 rt.Width ="Auto" \'表格宽度为自动,也就是等于各列设置宽度之和 rt.CanSplitHorz = True \'表格宽度超出页宽时,可以水平换页 rt.Style.Font = tb.Font For c As Integer = 0 To ColNames.Count - 1 \'逐列设置和填入内容 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 \'开始填入该列内容 rt.Cells(r + 1, c).Text = tb.Rows(r)(ColNames(c)) If (ColNames(c)) = "金额" rt.Cells(r + 1, c).Text = format(tb.Rows(r)(ColNames(c)),"00.00") 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 \'单元格内距设为0.5毫米 rt.Rows(0).Style.TextAlignHorz = prt.AlignHorzEnum.Center \'第一行内容水平居中 rt.RowGroups(0,1).Header = prt.TableHeaderEnum.All \'利用行组,将第一行设为表头. doc.Body.Children.Add(rt) \'将表格加入到报表 \'设置页眉 Dim rx As New prt.RenderTable rx.Cells(0,0).Text = Date.Today rx.Cells(0,1).Text = "" rx.Cells(0,2).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.right rx.Style.Borders.Bottom = New prt.LineDef \'设置底边框 rx.CellStyle.Spacing.Bottom = 0.5 \'底端内容缩进0.5毫米 rx.Style.FontSize = 8 \'字体大小为8磅 Doc.PageHeader = rx \'作为页眉使用 doc.Preview() \'预览
[此贴子已经被作者于2011-11-14 13:00:28编辑过]
|
-- 作者:狐狸爸爸
-- 发布时间:2011/11/15 9:18:00
--
呵呵,是比较难的,打开foxtable的演示文件:统计演示.table,在命令窗口执行:
Dim doc As New PrintDoc Dim tb As Table = Tables("订单") Dim prs As Integer = 20 \'每页20行 Dim sum1 As Integer = 0 Dim sum2 As Double = 0 For p As Integer = 0 To math.Ceiling(tb.Rows.Count / prs) - 1 Dim rt As New prt.RenderTable rt.Style.Gridlines.All = New prt.Linedef(Color.Gray) rt.CellStyle.Spacing.All = 0.5 For c As Integer = 0 To tb.Cols.Count - 1 rt.Cells(0,c).Text = tb.Cols(c).Name For r As Integer = p * prs To math.min(tb.Rows.Count - 1,( p + 1) * prs - 1) rt.Cells(r - p * prs + 1, c).Text = tb.rows(r)(c) Next Next sum1 = 0 sum2 = 0 For r As Integer = p * prs To math.min(tb.Rows.Count - 1,( p + 1) * prs - 1) sum1 =sum1 + tb.rows(r)("数量") sum2 =sum2 + tb.rows(r)("金额") Next rt.Rows.Count = rt.Rows.Count + 1 rt.Rows(rt.Rows.count -1)(0).text = "本页小计" rt.Rows(rt.Rows.count -1)(5).text = sum1 rt.Rows(rt.Rows.count -1)(6).text = sum2 If p < math.Ceiling(tb.Rows.Count / prs) - 1 rt.BreakAfter = prt.BreakEnum.Page End If doc.Body.Children.Add(rt) Next doc.Preview()
|