Foxtable(狐表)用户栏目专家坐堂 → [求助]专业报表插入小计行


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

主题:[求助]专业报表插入小计行

帅哥,在线噢!
程兴刚
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 一级勋章
等级:超级版主 帖子:7258 积分:40773 威望:0 精华:16 注册:2008/8/31 23:23:00
  发帖心情 Post By:2011/3/1 18:43:00 [显示全部帖子]

没时间弄,您也不给示例文件,调试费劲,给您一段示例代码,自己找合适的改编吧:

 

 

'''
Dim doc As New PrintDoc() '定义一个报表
'doc.PageSetting.Width = 210 '纸张宽度为100毫米
'doc.PageSetting.Height = 120 '纸张高度为120毫米
'doc.AutoRotate = False '禁止自动旋转打印内容
'doc.PageSetting.Landscape = True '横向打印
Doc.PageSetting.LeftMargin = 25 '设置左边距
Doc.PageSetting.RightMargin = 15 '设置右边距
Doc.PageSetting.TopMargin = 20 '设置上边距
Doc.PageSetting.BottomMargin = 0 '设置下边距
Dim rt As New prt.RenderTable() '定义一个表格对象
rt.Style.GridLines.All = New prt.LineDef '将网格线类型设为默认类型
rt.Style.TextAlignHorz = prt.AlignHorzEnum.Center '水平居中
rt.Style.TextAlignVert = prt.AlignVertEnum.Center '垂直居中
rt.Style.Spacing.Top = 4 '表格和前面对象的垂直间隔为4毫米
rt.Style.Spacing.Bottom = 10 '表和和后续对象的垂直间隔为10毫米
rt.Style.Spacing.All = 2
rt.y = "20mm"
rt.Style.GridLines.All = New Prt.LineDef(0.5,Color.Black)
rt.Style.GridLines.Horz = new Prt.LineDef(Color.Black)
rt.Style.GridLines.Vert = new Prt.LineDef(Color.Black)
rt.Rows.Count = 1 '设置行数
rt.Cols.Count = 6 '设置列数
rt.cols(2).Style.TextAlignHorz = prt.AlignHorzEnum.Right '水平靠右
rt.cols(3).Style.TextAlignHorz = prt.AlignHorzEnum.Right '水平靠右
rt.cols(4).Style.TextAlignHorz = prt.AlignHorzEnum.Right '水平靠右
rt.cols(5).Style.TextAlignHorz = prt.AlignHorzEnum.left '水平靠右
rt.cells(rt.Rows.Count-1,0).Text ="北京燕化集资建房幸福新村1#楼工程部门收支汇总表"
rt.Rows(rt.Rows.Count-1).Height = 13 & "mm"
rt.Rows(rt.Rows.Count-1).Style.GridLines.All = new Prt.LineDef(0,Color.Black)
rt.rows(rt.Rows.Count-1).Style.Font = New Font("宋体", 18,FontStyle.bold) '设置文本对象的字体
rt.Cells(rt.Rows.Count-1,0).SpanCols = 7 '第2行第2个单元格向右合并3列
rt.cells(rt.Rows.Count,0).Text = "第[PageNo]页,共[PageCount]页"
rt.Cells(rt.Rows.Count-1,0).SpanCols = 7 '第2行第2个单元格向右合并3列
rt.rows(rt.Rows.Count-1).Style.Font = New Font("黑体",12) '设置文本对象的字体
rt.Rows(rt.Rows.Count-1).Height = 6 & "mm"
rt.rows(rt.Rows.Count-1).Style.TextAlignHorz = prt.AlignHorzEnum.Right  '右对齐
rt.Rows(rt.Rows.Count-1).Style.GridLines.left = new Prt.LineDef(0,Color.Black)
rt.Rows(rt.Rows.Count-1).Style.GridLines.Right =new Prt.LineDef(0,Color.Black)
rt.cells(rt.Rows.Count,0).Text = "序号"
rt.cells(rt.Rows.Count-1,1).Text = "部门/姓名"
rt.cells(rt.Rows.Count-1,2).Text = "应付金额"
rt.cells(rt.Rows.Count-1,3).Text = "已付金额"
rt.cells(rt.Rows.Count-1,4).Text = "未付金额"
rt.cells(rt.Rows.Count-1,5).Text = "备  注"
rt.Rows(rt.Rows.Count-1).Height = 12 & "mm"
rt.rows(rt.Rows.Count-1).Style.Font = New Font("宋体", 12,FontStyle.bold) '设置文本对象的字体
rt.Rows(rt.Rows.Count-1).Style.BackColor = Color.LightGray '第一行背景颜色设为灰色.
rt.RowGroups(0,3).Header = prt.TableHeaderEnum.All '将前三行作为表头.
rt.Cols(0).Width = 12 & "mm"
rt.Cols(1).Width = 35 & "mm"
rt.Cols(2).Width = 35 & "mm"
rt.Cols(3).Width = 35 & "mm"
rt.Cols(4).Width = 35 & "mm"
rt.Cols(5).Width = 45 & "mm"
rt.cells(rt.Rows.Count,0).text = "总计金额:"
rt.Cells(rt.Rows.Count-1,0).SpanCols = 2 '第2行第2个单元格向右合并3列
rt.cells(rt.Rows.Count-1,2).text = format(DataTables("成本明细帐").Compute("Sum(金额)", "科目 = '应付款'"),"0.00")
rt.cells(rt.Rows.Count-1,3).text = format(DataTables("成本明细帐").Compute("Sum(金额)", "科目 = '已付款'"),"0.00")
rt.cells(rt.Rows.Count-1,4).text = format(DataTables("成本明细帐").Compute("Sum(金额)", "科目 = '应付款'")- DataTables("成本明细帐").Compute("Sum(金额)", "科目 = '已付款'"),"0.00")
rt.rows(rt.Rows.Count-1).Style.TextAlignHorz = prt.AlignHorzEnum.Center  '水平居中
rt.rows(rt.Rows.Count-1).Style.Font = New Font("宋体", 12,FontStyle.bold) '设置文本对象的字体
rt.Rows(rt.Rows.Count-1).Height = 12 & "mm"
Dim a,b As Integer

Dim Multi As String = DataTables("成本明细帐").GetComboListString("费用类别")
Dim Values() As String
Values = Multi.split("|")
For Index As Integer = 0 To Values.Length - 1
    a = DataTables("成本明细帐").Compute("Sum(金额)", "科目 = '应付款' and 费用类别 = '" & Values(Index)  & "'")
    b = DataTables("成本明细帐").Compute("Sum(金额)", "科目 = '已付款' and 费用类别 = '" & Values(Index)  & "'")
    If a = Nothing
        a = 0
    End If
    If b = Nothing
        b = 0
    End If
    rt.cells(rt.Rows.Count,0).text = "      其中:" & Values(Index) & ":"
    rt.cells(rt.Rows.Count-1,0).Style.TextAlignHorz = prt.AlignHorzEnum.left '水平居左
    rt.Cells(rt.Rows.Count-1,0).SpanCols = 2 '第2行第2个单元格向右合并3列
    rt.cells(rt.Rows.Count-1,2).text = format(a,"0.00")
    rt.cells(rt.Rows.Count-1,3).text = format(b,"0.00")
    rt.cells(rt.Rows.Count-1,4).text = format(a-b,"0.00")
    rt.Rows(rt.Rows.Count-1).Height = 8 & "mm"
Next
Multi = DataTables("成本明细帐").GetComboListString("部门或单位")
Values = Multi.split("|")
For Index As Integer = 0 To Values.Length - 1
    a = DataTables("成本明细帐").Compute("Sum(金额)", "科目 = '应付款' and 部门或单位 = '" & Values(Index) & "'")
    b = DataTables("成本明细帐
").Compute("Sum(金额)", "科目 = '已付款' and 部门或单位 = '" & Values(Index) & "'")
    If a = Nothing
        a = 0
    End If
    If b = Nothing
        b = 0
    End If
    rt.cells(rt.Rows.Count,0).text = format(Index+1,"000")
    rt.cells(rt.Rows.Count-1,1).text = Values(Index)
    rt.cells(rt.Rows.Count-1,2).text = format(a,"0.00")
    rt.cells(rt.Rows.Count-1,3).text = format(b,"0.00")
    rt.cells(rt.Rows.Count-1,4).text = format(a-b,"0.00")
    rt.Rows(rt.Rows.Count-1).Height = 6 & "mm"
    If e.Form.Controls("CheckBox1").Checked = True
        rt.Rows(rt.Rows.Count-1).Style.FontBold = True '字体加粗
        Dim drs As List(of DataRow) = DataTables("成本明细帐").Select("[部门或单位] = '" &  Values(Index) & "'","日期,科目 DESC")
        For Index1 As Integer = 0 To drs.Count-1
            rt.cells(rt.Rows.Count,0).text = "-" & format(Index1+1,"00")
            rt.cells(rt.Rows.Count-1,1).text = Values(Index)
            If drs(Index1)("科目") = "应付款"
                rt.cells(rt.Rows.Count-1,2).text = format(drs(Index1)("金额") ,"0.00")
            Else
                rt.cells(rt.Rows.Count-1,3).text = format(drs(Index1)("金额") ,"0.00")
            End If
            rt.cells(rt.Rows.Count-1,5).text = drs(Index1)("凭证号") & " " & drs(Index1)("费用类别") & " " &  drs(Index1)("备注")
            rt.cells(rt.Rows.Count-1,5).Style.Font = New Font("宋体",8) '设置文本对象的字体
            rt.cells(rt.Rows.Count-1,0).Style.TextAlignHorz = prt.AlignHorzEnum.Right  '右对齐
            rt.Rows(rt.Rows.Count-1).Height = 6 & "mm"
        Next
    End If
Next
rt.cells(rt.Rows.Count,0).text =  "      审  核:         记  帐:          经手人:            年    月    日"
rt.rows(rt.Rows.Count-1).Style.Font = New Font("宋体", 12,FontStyle.bold) '设置文本对象的字体
rt.Cells(rt.Rows.Count-1,0).SpanCols = 7 '第2行第2个单元格向右合并3列
rt.Rows(rt.Rows.Count-1).Style.GridLines.All = new Prt.LineDef(0,Color.Black)
rt.Rows(rt.Rows.Count-1).Style.GridLines.top = new Prt.LineDef(0.5,Color.Black)
rt.Rows(rt.Rows.Count-1).Height = 15 & "mm"
rt.RowGroups(rt.Rows.Count-1,1).Footer = prt.TableFooterEnum.All '利用行组,将最后一行设为表尾.
rt.cells(2,2).Style.TextAlignHorz = prt.AlignHorzEnum.Center '第一行内容水平居中
rt.cells(2,3).Style.TextAlignHorz = prt.AlignHorzEnum.Center '第一行内容水平居中
rt.cells(2,4).Style.TextAlignHorz = prt.AlignHorzEnum.Center '第一行内容水平居中
rt.cells(2,5).Style.TextAlignHorz = prt.AlignHorzEnum.Center '第一行内容水平居中
doc.Body.Children.Add(rt) '将表格对象加入到报表中
Doc.Preview() '预览报表

[此贴子已经被作者于2011-3-1 18:45:03编辑过]

 回到顶部