以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  想偷个懒,求个专业报表的通用代码  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=28418)

--  作者:even0898
--  发布时间:2013/1/28 22:00:00
--  想偷个懒,求个专业报表的通用代码

1.可以分页小计金额列,最后一页总计金额列

2.控制每页X行

3.排除隐藏列

实例里分开来了,for ..next的嵌套实在头晕,自己组合了N次还是不得其法,求高手给个现成的


--  作者:even0898
--  发布时间:2013/1/28 22:11:00
--  
Dim tb As Table = Tables("客户对账单主表.客户对账单明细")
Dim ColNames As New List(Of String)
Dim sum As Double = 0 \'金额小计
Dim tsum As Double = 0 \'金额总计
Dim idx As Integer= tb.cols("金额").Index
Dim prs As Integer = 50
For p As Integer = 0 To math.Ceiling(tb.Rows.Count / prs) - 1
    Dim rx As New prt.RenderTable
    For Each cl As Col In tb.Cols \'排除隐藏列
        If cl.Visible Then
            ColNames.Add(cl.Name)
        End If
    Next
    rx.Width = "Auto" \'表格宽度为自动,也就是等于各列设置宽度之和
    rx.Style.Font = tb.Font
    For c As Integer = 0 To ColNames.Count - 1 \'逐列设置和填入内容
        rx.Cells(0,c).Text = ColNames(c) \'列名作为标题
        rx.Cells(0,c).Style.TextAlignHorz = prt.AlignHorzEnum.Center \'标题内容水平居中
        rx.Cols(c).Width = tb.Cols(ColNames(c)).PrintWidth \'列宽等于实际列宽
        rx.Cols(c).Style.TextAlignHorz = prt.AlignHorzEnum.left \'数据水平靠右
        For r As Integer = 0 To tb.Rows.Count - 1 \'开始填入该列内容
            rx.Cells(r + 1, c).Text = tb.Rows(r)(ColNames(c))
        Next
    Next
    sum = 0
    For i As Integer = p * prs To math.min(tb.Rows.Count - 1,( p + 1) * prs - 1)
        sum =sum + tb.rows(i)("金额")
        For v As Integer = 0 To tb.Cols.Count - 1
            rx.Cells(i - p * prs + 1, v).Text = tb.rows(i)(v)
        Next
    Next
    tsum = tsum + sum
    rx.Rows.Count = rx.Rows.Count + 1 \'增加本页小计行
    rx.Rows(rx.Rows.count -1)(0).text = "本页小计"
    rx.Rows(rx.Rows.count -1)(idx).text = sum
    If p = math.Ceiling(tb.Rows.Count / prs) - 1 \'如果是最后一页
        rx.Rows.Count = rx.Rows.Count + 1 \'增加总计行
        rx.Rows(rx.Rows.count -1)(0).text = "总计"
        rx.Rows(rx.Rows.count -1)(idx).text = tsum
    Else
        rx.BreakAfter = prt.BreakEnum.Page \'否则换页
    End If
    rx.Cols.Insert(0) \'在左边插入一列,用于打印行号
    rx.Cols(0).Width = 8 \'设置行号列的宽度
    For i As Integer = 1 To rx.Rows.Count - 1
        rx.Cells(i,0).text = i \'逐行写入行号
    Next
    rx.Style.Gridlines.All = New prt.Linedef(Color.Gray) \'灰色网格线
    rx.CellStyle.Spacing.All = 0.5 \'单元格内距设为0.5毫米
    rx.Rows(0).Style.TextAlignHorz = prt.AlignHorzEnum.Center \'第一行内容水平居中
    rx.RowGroups(0,1).Header = prt.TableHeaderEnum.All \'利用行组,将第一行设为表头.
    doc.Body.Children.Add(rx) \'将表格加入到报表
Next
这样写报表被统计了3次,而且隐藏列没有排除掉,分页小计只在最后一页出现,求解...

--  作者:lin_hailun
--  发布时间:2013/1/29 10:22:00
--  
 小例子,代码自己修改一下。

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:分页统计.table