以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 专业报表的统计问题 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=187776) |
|
-- 作者:lin98 -- 发布时间:2023/8/10 16:16:00 -- 专业报表的统计问题 Dim doc As New Printdoc Dim rx As prt.RenderText Dim rt As prt.RenderTable Dim Rows As List(Of DataRow) Dim tbl As Table = Tables("销售主表") For i As Integer = tbl.TopRow To tbl.BottomRow rx = New prt.RenderText \' rx.BreakBefore = prt.BreakEnum.Page \'另起一页再打印 rx.Style.FontSize = 14 rx.Style.FontBold = True rx.Style.Spacing.Bottom = 5 rx.Text = "公司名称: " & Tables("销售主表").Rows(i)("公司名称") doc.Body.Children.Add(rx) rt = New prt.RenderTable rt.Style.TextAlignHorz = prt.AlignHorzEnum.Center rt.Style.TextAlignVert = prt.AlignVertEnum.Center rt.Style.Borders.Bottom = New prt.LineDef(0.3, Color.LightGray) rt.CellStyle.Spacing.All = 1 rt.Cols.Count = 4 rt.Cells(0, 0).Text = "产品" rt.Cells(0, 1).Text = "客户" rt.Cells(0, 2).Text = "雇员" rt.Cells(0, 3).Text = "单价" rt.Cells(0, 4).Text = "折扣" rt.Cells(0, 5).Text = "数量" rt.rows(0).Style.Borders.Top = New prt.LineDef(1, Color.LightGray) rt.rows(0).Style.Borders.Bottom = New prt.LineDef(1, Color.LightGray) Rows = DataTables("销售明细").select("客户=\'" & Tables("销售主表").Rows(i)("公司名称") & "\'") For r As Integer = 0 To Rows.Count - 1 rt.Cells(r + 1, 0).Text = rows(r)("产品") rt.Cells(r + 1, 1).Text = rows(r)("客户") rt.Cells(r + 1, 2).Text = rows(r)("雇员") rt.Cells(r + 1, 3).Text = rows(r)("单价") rt.Cells(r + 1, 4).Text = rows(r)("折扣") rt.Cells(r + 1, 4).Text = rows(r)("数量") Next doc.Body.Children.Add(rt) rx = New prt.RenderText rx.Style.FontBold = True rx.Style.Spacing.Top = 3 rx.Text = "销售明细数目: " & Rows.Count rx.Style.TextAlignHorz = prt.AlignHorzEnum.Right doc.Body.Children.Add(rx) Next doc.Preview 如何实现表尾合计? |
|
-- 作者:有点蓝 -- 发布时间:2023/8/10 16:18:00 -- 参考这里方法增加合计行:http://www.foxtable.com/webhelp/topics/2239.htm |
|
-- 作者:lin98 -- 发布时间:2023/8/10 16:48:00 -- 加上下面代码,合计错,都是一个数据,如何解决?谢谢 Dim cnt As Integer cnt = rt.Rows.Count rt.Cells(cnt, 0).Text = "合计 " \'打印产品的小计 rt.Cells(cnt, 5).Text = tb.compute("Sum(数量)") |
|
-- 作者:有点蓝 -- 发布时间:2023/8/10 17:03:00 -- 统计的时候加上公司名称条件 |
|
-- 作者:lin98 -- 发布时间:2023/8/10 17:24:00 -- Dim cnt As Integer cnt = rt.Rows.Count rt.Cells(cnt, 0).Text = "合计 " \'打印产品的小计 \' rt.Cells(cnt, 5).Text = tb.compute("Sum(数量)", "产品 = \'" & pd & "\'") rt.Cells(cnt, 5).Text = tb.compute("Sum(数量)", ("公司名称") & "\'") 没有统计,还是不行
|
|
-- 作者:有点蓝 -- 发布时间:2023/8/10 17:33:00 -- 自己写过的代码,换个地方就不会了? |
|
-- 作者:lin98 -- 发布时间:2023/8/10 18:07:00 -- 位置一: For r As Integer = 0 To Rows.Count - 1 rt.Cells(r + 1, 0).Text = rows(r)("产品") rt.Cells(r + 1, 1).Text = rows(r)("客户") rt.Cells(r + 1, 2).Text = rows(r)("雇员") rt.Cells(r + 1, 3).Text = rows(r)("单价") rt.Cells(r + 1, 4).Text = rows(r)("折扣") rt.Cells(r + 1, 4).Text = rows(r)("数量") Dim cnt As Integer cnt = rt.Rows.Count rt.Cells(cnt, 0).Text = "合计 " \'打印产品的小计 \' rt.Cells(cnt, 5).Text = tb.compute("Sum(数量)", "产品 = \'" & pd & "\'") rt.Cells(cnt, 5).Text = tb.compute("Sum(数量)", ("客户=\'" & Tables("销售主表").Rows(i)("公司名称") & "\'")) Next doc.Body.Children.Add(rt) rx = New prt.RenderText rx.Style.FontBold = True rx.Style.Spacing.Top = 3 rx.Text = "销售明细数目: " & Rows.Count rx.Style.TextAlignHorz = prt.AlignHorzEnum.Right doc.Body.Children.Add(rx) Next 位置2: For r As Integer = 0 To Rows.Count - 1 rt.Cells(r + 1, 0).Text = rows(r)("产品") rt.Cells(r + 1, 1).Text = rows(r)("客户") rt.Cells(r + 1, 2).Text = rows(r)("雇员") rt.Cells(r + 1, 3).Text = rows(r)("单价") rt.Cells(r + 1, 4).Text = rows(r)("折扣") rt.Cells(r + 1, 4).Text = rows(r)("数量") Next Dim cnt As Integer cnt = rt.Rows.Count rt.Cells(cnt, 0).Text = "合计 " \'打印产品的小计 \' rt.Cells(cnt, 5).Text = tb.compute("Sum(数量)", "产品 = \'" & pd & "\'") rt.Cells(cnt, 5).Text = tb.compute("Sum(数量)", ("客户=\'" & Tables("销售主表").Rows(i)("公司名称") & "\'")) doc.Body.Children.Add(rt) rx = New prt.RenderText rx.Style.FontBold = True rx.Style.Spacing.Top = 3 rx.Text = "销售明细数目: " & Rows.Count rx.Style.TextAlignHorz = prt.AlignHorzEnum.Right doc.Body.Children.Add(rx) Next 还是不行,只一个有合计,其他都没有合计 |
|
-- 作者:有点蓝 -- 发布时间:2023/8/10 20:36:00 -- 数据应该是来自哪个表的,上面代码统计的又是哪个表 |
|
-- 作者:lin98 -- 发布时间:2023/8/10 21:26:00 --
|
|
-- 作者:lin98 -- 发布时间:2023/8/10 23:44:00 -- 需求:1楼的代码如何实现自动补空行? 一楼的代码结合下面代码,如何实现自动补空行? Dim doc As New PrintDoc Dim tb As Table = Tables("销售明细") Dim prs As Integer = 20 \'每页20行 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 Next For r As Integer = p * prs To math.min(tb.Rows.Count - 1,( p + 1) * prs - 1) For c As Integer = 0 To tb.Cols.Count - 1 rt.Cells(r - p * prs + 1, c).Text = tb.rows(r)(c) Next Next If p = math.Ceiling(tb.Rows.Count / prs) - 1 \'如果是最后一页 For r As Integer = tb.Rows.Count To ( p + 1) * prs - 1 \'补空行 rt.Rows.Count = rt.Rows.Count + 1 rt.Rows(rt.Rows.count -1)(0).text = " " Next Else rt.BreakAfter = prt.BreakEnum.Page \'否则换页 End If doc.Body.Children.Add(rt) Next doc.Preview()
[此贴子已经被作者于2023/8/10 23:43:47编辑过]
|