以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]下面这段代码,能实现自定义各列列宽,和分页汇总吗?  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=27043)

--  作者:99473593
--  发布时间:2012/12/20 15:48:00
--  [求助]下面这段代码,能实现自定义各列列宽,和分页汇总吗?

求助,下面报表代码,我想实现能够定义各列列宽,和在每页的最后一行显示当前页的点货金额,本单应收款小计,在报表的最后一行显示总计,能实现吗,代码改怎么改呀。我很菜,求高手指点。。。。。

---------------------------------------------------------------

Dim doc As New PrintDoc \'定义一个新报表
Dim rt As New prt.RenderTable \'定义一个新表格
Dim tb As Table = Tables("订单执行跟踪") \'指定数据来源
\'指定报表显示列
Dim ColNames(10) As String
ColNames(0) = "发货日期"
ColNames(1) = "执行单号"
ColNames(2) = "客户名称"
ColNames(3) = "配货员"
ColNames(4) = "点货员"
ColNames(5) = "点货金额"
ColNames(6) = "本单应收款"
ColNames(7) = "收款日期"
ColNames(8) = "收款帐户"
ColNames(9) = "收款金额"
ColNames(10) = "件数"
\'表格格式设置
rt.Width = "Auto" \'表格宽度为自动,也就是等于各列设置宽度之和
rt.SplitHorzBehavior = prt.SplitBehaviorEnum.SplitIfNeeded \'表格宽度超出页宽时,可以水平换页
rt.Style.Font = tb.Font
For c As Integer = 0 To ColNames.Length - 1 \'逐列设置和填入内容
    rt.Cells(0,c).Text = ColNames(c) \'列名作为标题
    rt.Rows(0).Style.BackColor = Color.LightGray \'第一行背景颜色设为灰色
    rt.RowGroups(0,1).Header = prt.TableHeaderEnum.All \'利用行组,将第一行设为表头.
    rt.Cells(0,c).Style.TextAlignHorz = prt.AlignHorzEnum.Center \'标题内容水平居中
    rt.Cols(c).Width = tb.Cols(ColNames(c)).PrintWidth \'列宽等于实际列宽
    rt.Style.Gridlines.All = New prt.Linedef(Color.Gray) \'灰色网格线
    rt.CellStyle.Spacing.All = 2 \'单元格内距设为0.5毫米
    rt.Rows(0).Style.TextAlignHorz = prt.AlignHorzEnum.Center \'第一行内容水平居中
    rt.RowGroups(0,1).Header = prt.TableHeaderEnum.All \'利用行组,将第一行设为表头.
    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))
    Next
Next
\'打印行号
rt.Cols.Insert(0) \'在左边插入一列,用于打印行号
rt.Cols(0).Width = 12 \'设置行号列的宽度
For i As Integer = 1 To rt.Rows.Count - 1
    rt.Cells(i,0).text = i \'逐行写入行号
Next


\'报表版面设置
doc.PageSetting.Landscape = True \'横向打印
Doc.PageSetting.LeftMargin = 10 \'设置左边距
Doc.PageSetting.RightMargin = 0 \'设置右边距
Doc.PageSetting.TopMargin = 10 \'设置上边距
Doc.PageSetting.BottomMargin = 0 \'设置下边距
doc.PageSetting.PaperKind = 9 \'纸张类型改为A4
doc.Body.Children.Add(rt) \'将表格加入到报表
Dim x As Integer = 0 \'定义水平偏移参数
Dim y As Integer = 0 \'定义垂直偏移参数

\'如果需要分栏打印,请加上下面两行
\'doc.Columns.Add()
\'doc.Columns.Add()


\'设置页眉
Dim rx As New prt.RenderTable
rx.Cells(1,0).Text = Date.Today
rx.Cells(0,1).Text = "发货月明细报表"
rx.Cells(1,2).Text = "第[PageNo]页,共[PageCount]页"
rx.Style.Spacing.Bottom = 5 \'和下面的对象(表格)距离3毫米
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.CellStyle.Spacing.Bottom = 0.5 \'底端内容缩进0.5毫米
rx.Style.FontSize = 18 \'字体大小为8磅
Doc.PageHeader = rx \'作为页眉使用
doc.Preview()


--  作者:lin_hailun
--  发布时间:2012/12/20 16:14:00
--  
看红色编辑提示。

Dim doc As New PrintDoc \'定义一个新报表
Dim rt As New prt.RenderTable \'定义一个新表格
Dim tb As Table = Tables("订单执行跟踪") \'指定数据来源
\'指定报表显示列
Dim ColNames(10) As String
ColNames(0) = "发货日期"
ColNames(1) = "执行单号"
ColNames(2) = "客户名称"
ColNames(3) = "配货员"
ColNames(4) = "点货员"
ColNames(5) = "点货金额"
ColNames(6) = "本单应收款"
ColNames(7) = "收款日期"
ColNames(8) = "收款帐户"
ColNames(9) = "收款金额"
ColNames(10) = "件数"


Dim ColWidths(10) As Double = {10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10}


\'表格格式设置
rt.Width = "Auto" \'表格宽度为自动,也就是等于各列设置宽度之和
rt.SplitHorzBehavior = prt.SplitBehaviorEnum.SplitIfNeeded \'表格宽度超出页宽时,可以水平换页
rt.Style.Font = tb.Font
For c As Integer = 0 To ColNames.Length - 1 \'逐列设置和填入内容
    rt.Cells(0,c).Text = ColNames(c) \'列名作为标题
    rt.Rows(0).Style.BackColor = Color.LightGray \'第一行背景颜色设为灰色
    rt.RowGroups(0,1).Header = prt.TableHeaderEnum.All \'利用行组,将第一行设为表头.
    rt.Cells(0,c).Style.TextAlignHorz = prt.AlignHorzEnum.Center \'标题内容水平居中
    rt.Cols(c).Width = tb.Cols(ColNames(c)).PrintWidth \'列宽等于实际列宽

    rt.Cols(c).Width = ColWidths(c)

    rt.Style.Gridlines.All = New prt.Linedef(Color.Gray) \'灰色网格线
    rt.CellStyle.Spacing.All = 2 \'单元格内距设为0.5毫米
    rt.Rows(0).Style.TextAlignHorz = prt.AlignHorzEnum.Center \'第一行内容水平居中
    rt.RowGroups(0,1).Header = prt.TableHeaderEnum.All \'利用行组,将第一行设为表头.
    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))
    Next
Next
\'打印行号
rt.Cols.Insert(0) \'在左边插入一列,用于打印行号
rt.Cols(0).Width = 12 \'设置行号列的宽度
For i As Integer = 1 To rt.Rows.Count - 1
    rt.Cells(i,0).text = i \'逐行写入行号
Next


\'报表版面设置
doc.PageSetting.Landscape = True \'横向打印
Doc.PageSetting.LeftMargin = 10 \'设置左边距
Doc.PageSetting.RightMargin = 0 \'设置右边距
Doc.PageSetting.TopMargin = 10 \'设置上边距
Doc.PageSetting.BottomMargin = 0 \'设置下边距
doc.PageSetting.PaperKind = 9 \'纸张类型改为A4
doc.Body.Children.Add(rt) \'将表格加入到报表
Dim x As Integer = 0 \'定义水平偏移参数
Dim y As Integer = 0 \'定义垂直偏移参数

\'如果需要分栏打印,请加上下面两行
\'doc.Columns.Add()
\'doc.Columns.Add()


\'设置页眉
Dim rx As New prt.RenderTable
rx.Cells(1,0).Text = Date.Today
rx.Cells(0,1).Text = "发货月明细报表"
rx.Cells(1,2).Text = "第[PageNo]页,共[PageCount]页"
rx.Style.Spacing.Bottom = 5 \'和下面的对象(表格)距离3毫米
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.CellStyle.Spacing.Bottom = 0.5 \'底端内容缩进0.5毫米
rx.Style.FontSize = 18 \'字体大小为8磅
Doc.PageHeader = rx \'作为页眉使用

\'设置页脚
Dim rx As New prt.RenderTable
rx.Cells(1,0).Text = Date.Today
rx.Cells(0,1).Text = "页脚"
rx.Cells(1,2).Text = "自己编写统计,不清楚你的数据,亲"
rx.Style.Spacing.Bottom = 5 \'和下面的对象(表格)距离3毫米
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.CellStyle.Spacing.Bottom = 0.5 \'底端内容缩进0.5毫米
rx.Style.FontSize = 18 \'字体大小为8磅
Doc. PageFooter = rx \'作为页眉使用


doc.Preview()

--  作者:99473593
--  发布时间:2012/12/20 16:34:00
--  

好像不行,我不知道问题出在哪呢


--  作者:lin_hailun
--  发布时间:2012/12/20 17:30:00
--  
 呃,不要只贴出代码。

 正确的提问方式是,你要有例子——至少你要上传一些测试的数据。