Foxtable(狐表)用户栏目专家坐堂 → [求助]专业报表,自动补空行(已解决)


  共有12235人关注过本帖树形打印复制链接

主题:[求助]专业报表,自动补空行(已解决)

帅哥哟,离线,有人找我吗?
yyzlxc
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:七尾狐 帖子:1530 积分:10639 威望:0 精华:0 注册:2008/9/24 11:16:00
[求助]专业报表,自动补空行(已解决)  发帖心情 Post By:2011/11/30 20:21:00 [只看该作者]

根据狐爸老师在论坛的一段“自动补空行”的代码,移植过来(黄色标记)后不起作用,不知问题出在哪里,请各位老师指教,谢谢!!

 

Dim doc As New PrintDoc '定义一个新报表
Dim tb As Table = Tables("订单")  '捆绑表
Dim prs As Integer = 40   '每页40行
Dim sum1 As Integer = 0  '定义整数变量(小计)
Dim sum2 As Double = 0 '定义双精度变量(小计)
Dim tsum1 As Integer = 0  '定义整数变量(合计)
Dim tsum2 As Double = 0 '定义双精度变量(合计)
For p As Integer = 0 To math.Ceiling(tb.Rows.Count / prs) - 1  '大循环,计算共几页
    Dim ColNames As String() = {"日期","产品","单价","折扣","数量","金额"}
    Dim rt As New prt.RenderTable   '定义一个新表格
    rt.Width = "Parent.Width" '表格宽度等于容器宽度
    rt.CanSplitHorz = True  '表格宽度超出页宽时,可以水平换页
    rt.Style.Font = tb.Font
    rt.Style.Gridlines.All = New prt.Linedef(Color.Gray)  '灰色网格线
    rt.CellStyle.Spacing.All = 1.0   '单元格内距设为1.0毫米
    For i As Integer = 0 To ColNames.Length -1 '逐列设置和填入内容
        rt.Cells(0,i).Text = ColNames(i)   '列名作为标题
        rt.Cells(0,i).Style.TextAlignHorz = prt.AlignHorzEnum.Center   '标题内容水平居中
       
        rt.Cols(i).Width = tb.Cols(ColNames(i)).PrintWidth '列宽等于实际列宽
        If tb.Cols(ColNames(i)).IsNumeric Then '如果是数值
            rt.Cols(i).Style.TextAlignHorz = prt.AlignHorzEnum.Right '数据水平靠右
        Else
            rt.Cols(i).Style.TextAlignHorz = prt.AlignHorzEnum.Center  '数据水平居中
        End If
        For r As Integer = p * prs To math.min(tb.Rows.Count - 1,( p + 1) * prs - 1)  '小循环
            rt.Cells(r - p * prs + 1, i).Text = tb.rows(r)(ColNames(i))
            If (ColNames(i)) = "数量" '设置格式
                rt.Cells(r - p * prs + 1, i).Text = format(tb.rows(r)(ColNames(i)),"0")
            ElseIf (ColNames(i)) = "单价"
                rt.Cells(r - p * prs + 1, i).Text = format(tb.rows(r)(ColNames(i)),"0.00")
            ElseIf (ColNames(i)) = "折扣"
                rt.Cells(r - p * prs + 1, i).Text = format(tb.rows(r)(ColNames(i)),"0.00")
            ElseIf (ColNames(i)) = "金额"
                rt.Cells(r - p * prs + 1, i).Text = format(tb.rows(r)(ColNames(i)),"0.00")
            Else
                rt.Cells(r - p * prs + 1, i).Text = tb.rows(r)(ColNames(i))
            End If
        Next

        If i = 0 Then '加空行
            For r As Integer = tb.Rows.Count To prs
                rt.Cells(r - p * prs + 1, 0).Text = " "
            Next
        End If

    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
    Tsum1 = tsum1 + sum1
    tsum2 = tsum2 + sum2
    rt.Rows.Count = rt.Rows.Count + 1 '增加小计行
    rt.Rows(rt.Rows.count -1)(3).text = "本页小计"
    rt.Rows(rt.Rows.count -1)(4).Text = format(sum1,"0")  '设置小计格式
    rt.Rows(rt.Rows.count -1)(5).Text = format(sum2,"0.00")
    If p < math.Ceiling(tb.Rows.Count / prs) - 1
        rt.BreakAfter = prt.BreakEnum.Page
    Else
        rt.Rows.Count = rt.Rows.Count + 1 '增加合计行
        rt.Rows(rt.Rows.count -1)(3).text = "合计"
        rt.Rows(rt.Rows.count -1)(4).Text = format(tsum1,"0") '设置合计格式
        rt.Rows(rt.Rows.count -1)(5).Text = format(tsum2,"0.00")
    End If
    doc.Body.Children.Add(rt)  '将表格加入到报表
Next
'设置页眉
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(0).Style.TextAlignVert = prt.AlignVertEnum.Bottom '垂直靠下
rx.Cols(1).Style.TextAlignHorz = prt.AlignHorzEnum.Center '水平居中
rx.Cols(2).Style.TextAlignHorz = prt.AlignHorzEnum.right '水平靠右
rx.Cols(2).Style.TextAlignVert = prt.AlignVertEnum.Bottom '垂直靠下
rx.Style.Borders.Bottom = New prt.LineDef '设置底边框
rx.CellStyle.Spacing.Bottom = 1 '底端内容缩进1.0毫米
rx.Cells(0,1).Style.FontSize = 14  '设置第二列行字号
rx.Cells(0,1).Style.FontBold = True '字体加粗
Doc.PageHeader = rx '作为页眉使用
Doc.Preview() '预览

[此贴子已经被作者于2011-12-1 8:39:57编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
yyzlxc
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:七尾狐 帖子:1530 积分:10639 威望:0 精华:0 注册:2008/9/24 11:16:00
  发帖心情 Post By:2011/11/30 22:19:00 [只看该作者]

这是狐爸老师的原代码:

 

Dim doc As New PrintDoc
Dim rt As New prt.RenderTable
Dim MinRows As Integer = 20
Dim tb As Table = Tables("表A")
For c As Integer = 0 To tb.Cols.Count -1 '逐列填入内容
    rt.Cells(0,c).Text = tb.Cols(c).Name '列名作为标题
    For r As Integer = 0 To tb.Rows.Count -1
        rt.Cells(r + 1, c).Text = tb(r,c)
    Next
    IF c = 0 Then '加空行
        For  r As Integer = tb.Rows.Count To MinRows
            rt.Cells(r+1,0).Text = " "
        Next
    End If
Next
rt.Style.Gridlines.All = New prt.Linedef(Color.Gray) '灰色网格线
doc.Body.Children.Add(rt)
doc.Preview()


 回到顶部
帅哥哟,离线,有人找我吗?
czy
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 一级勋章 三级勋章 二级勋章
等级:超级版主 帖子:6318 积分:33963 威望:0 精华:10 注册:2008/8/31 20:56:00
  发帖心情 Post By:2011/11/30 23:14:00 [只看该作者]

Dim doc As New PrintDoc '定义一个新报表
Dim tb As Table = Tables("订单")  '捆绑表
Dim prs As Integer = 40   '每页40行
Dim sum1 As Integer = 0  '定义整数变量(小计)
Dim sum2 As Double = 0 '定义双精度变量(小计)
Dim tsum1 As Integer = 0  '定义整数变量(合计)
Dim tsum2 As Double = 0 '定义双精度变量(合计)
For p As Integer = 0 To math.Ceiling(tb.Rows.Count / prs) - 1  '大循环,计算共几页
    Dim ColNames As String() = {"日期","产品","单价","折扣","数量","金额"}
    Dim rt As New prt.RenderTable   '定义一个新表格
    rt.Width = "Parent.Width" '表格宽度等于容器宽度
    rt.CanSplitHorz = True  '表格宽度超出页宽时,可以水平换页
    rt.Style.Font = tb.Font
    rt.Style.Gridlines.All = New prt.Linedef(Color.Gray)  '灰色网格线
    rt.CellStyle.Spacing.All = 1.0   '单元格内距设为1.0毫米
    For i As Integer = 0 To ColNames.Length -1 '逐列设置和填入内容
        rt.Cells(0,i).Text = ColNames(i)   '列名作为标题
        rt.Cells(0,i).Style.TextAlignHorz = prt.AlignHorzEnum.Center   '标题内容水平居中
       
        rt.Cols(i).Width = tb.Cols(ColNames(i)).PrintWidth '列宽等于实际列宽
        If tb.Cols(ColNames(i)).IsNumeric Then '如果是数值
            rt.Cols(i).Style.TextAlignHorz = prt.AlignHorzEnum.Right '数据水平靠右
        Else
            rt.Cols(i).Style.TextAlignHorz = prt.AlignHorzEnum.Center  '数据水平居中
        End If
        For r As Integer = p * prs To math.min(tb.Rows.Count - 1,( p + 1) * prs - 1)  '小循环
            rt.Cells(r - p * prs + 1, i).Text = tb.rows(r)(ColNames(i))
            If (ColNames(i)) = "数量" '设置格式
                rt.Cells(r - p * prs + 1, i).Text = format(tb.rows(r)(ColNames(i)),"0")
            ElseIf (ColNames(i)) = "单价"
                rt.Cells(r - p * prs + 1, i).Text = format(tb.rows(r)(ColNames(i)),"0.00")
            ElseIf (ColNames(i)) = "折扣"
                rt.Cells(r - p * prs + 1, i).Text = format(tb.rows(r)(ColNames(i)),"0.00")
            ElseIf (ColNames(i)) = "金额"
                rt.Cells(r - p * prs + 1, i).Text = format(tb.rows(r)(ColNames(i)),"0.00")
            Else
                rt.Cells(r - p * prs + 1, i).Text = tb.rows(r)(ColNames(i))
            End If
        Next
        If i = 0 Then '加空行
            For r As Integer = tb.Rows.Count  To prs * (p+1) -1
                rt.Cells((r - p) * prs, 0).Text = " "
            Next

        End If
    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
    Tsum1 = tsum1 + sum1
    tsum2 = tsum2 + sum2
    rt.Rows.Count = rt.Rows.Count + 1 '增加小计行
    rt.Rows(rt.Rows.count -1)(3).text = "本页小计"
    rt.Rows(rt.Rows.count -1)(4).Text = format(sum1,"0")  '设置小计格式
    rt.Rows(rt.Rows.count -1)(5).Text = format(sum2,"0.00")
    If p < math.Ceiling(tb.Rows.Count / prs) - 1
        rt.BreakAfter = prt.BreakEnum.Page
    Else
        rt.Rows.Count = rt.Rows.Count + 1 '增加合计行
        rt.Rows(rt.Rows.count -1)(3).text = "合计"
        rt.Rows(rt.Rows.count -1)(4).Text = format(tsum1,"0") '设置合计格式
        rt.Rows(rt.Rows.count -1)(5).Text = format(tsum2,"0.00")
    End If
    doc.Body.Children.Add(rt)  '将表格加入到报表
Next
'设置页眉
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(0).Style.TextAlignVert = prt.AlignVertEnum.Bottom '垂直靠下
rx.Cols(1).Style.TextAlignHorz = prt.AlignHorzEnum.Center '水平居中
rx.Cols(2).Style.TextAlignHorz = prt.AlignHorzEnum.right '水平靠右
rx.Cols(2).Style.TextAlignVert = prt.AlignVertEnum.Bottom '垂直靠下
rx.Style.Borders.Bottom = New prt.LineDef '设置底边框
rx.CellStyle.Spacing.Bottom = 1 '底端内容缩进1.0毫米
rx.Cells(0,1).Style.FontSize = 14  '设置第二列行字号
rx.Cells(0,1).Style.FontBold = True '字体加粗
Doc.PageHeader = rx '作为页眉使用
Doc.Preview() '预览

 回到顶部
帅哥哟,离线,有人找我吗?
yyzlxc
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:七尾狐 帖子:1530 积分:10639 威望:0 精华:0 注册:2008/9/24 11:16:00
  发帖心情 Post By:2011/12/1 8:40:00 [只看该作者]

谢谢czy老师,问题解决。看来专业报表太深奥了,变化无穷,并不像帮助里讲的那么简单,通过这一案例,也看到狐表的魅力,令人感慨万分。再次感谢czy老师的辛勤的劳动,让我们领略了狐表的风采。

 回到顶部