Foxtable(狐表)用户栏目专家坐堂 → 专业报表表头的问题(如何连续打印)


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

主题:专业报表表头的问题(如何连续打印)

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


加好友 发短信
等级:四尾狐 帖子:976 积分:8527 威望:0 精华:0 注册:2012/2/9 16:35:00
  发帖心情 Post By:2014/1/4 8:35:00 [只看该作者]

再次请教程版,这种通用格式的如果是主表选择多行要实现主子表的数据连续打印时:
For i As Integer = tbl.TopRow To tbl.BottomRow遍历的语句要怎么加,试了很久,结果都不正确?

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


加好友 发短信 一级勋章
等级:超级版主 帖子:7237 积分:40614 威望:0 精华:16 注册:2008/8/31 23:23:00
  发帖心情 Post By:2014/1/4 10:07:00 [只看该作者]

贴出您调整好的代码!


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


加好友 发短信
等级:四尾狐 帖子:976 积分:8527 威望:0 精华:0 注册:2012/2/9 16:35:00
  发帖心情 Post By:2014/1/4 11:00:00 [只看该作者]

谢谢,又仔细学习了下。还是不正确

即选择两行主表打印时第二行(客户B)的子表应该只有三行数据,却显示第一行的数据了。


Dim doc As New PrintDoc '定义一个报表
Dim Mtb As Table = Tables("订单")
Dim tb As Table = Tables("订单.订单明细")
For n As Integer = Tables("订单").TopRow To Tables("订单").BottomRow
    Dim CurRow As Row = Tables("订单").rows(n) '获取当前行
    '设置打印纸张
    doc.PageSetting.PaperKind = 9  'A4
    'doc.PageSetting.Width = 210 '纸张宽度毫米
    'doc.PageSetting.Height = 290 '纸张高度毫米
    doc.PageSetting.Landscape = True '是否横向打印
    Doc.PageSetting.LeftMargin = 10 '设置左边距
    Doc.PageSetting.RightMargin = 10 '设置右边距
    Doc.PageSetting.TopMargin = 8 '设置上边距
    Doc.PageSetting.BottomMargin = 8 '设置下边距
    Dim rt As New prt.RenderTable() '定义一个表格对象
    '---------------------------------指定第一个表行数,列数,
    rt.Cols.Count = 15 '设置总列数
    '---------------------------------设置指定行的列宽,未指定的平分剩余宽度
    Dim CW As String = "20|12|12|25|20|15|30|15|15|15|15|10"
    Dim Cls As String() = CW.split("|")
    For i As Integer = 0 To Cls.Length-1
        rt.Cols(i).Width = Cls(i)
    Next
    '设置表格总体样式
    rt.Style.TextAlignHorz = prt.AlignHorzEnum.Center '文本水平居中
    rt.Style.TextAlignVert = prt.AlignVertEnum.Center '文本垂直居中
    rt.CellStyle.Spacing.All = 1 '单元格内容缩进1毫米
    rt.Style.GridLines.All = New prt.Linedef(0.3,Color.Black) '设置网格线
    rt.Style.Font = New Font("宋体", 12) '设置总体字体
    'rt.SplitVertBehavior = prt.SplitBehaviorEnum.Never '禁止被垂直分割
    rt.SplitHorzBehavior = prt.SplitBehaviorEnum.SplitIfNeeded '表格宽度超出页宽时,可以水平换页
    '设置主标题------------------------------------------------1
    rt.Rows(rt.Rows.Count).Height = 12
    rt.Rows(rt.Rows.Count-1).Style.Borders.All = New prt.LineDef("0mm", Color.white) '去掉网格线
    rt.Cells(rt.Rows.Count-1,0).SpanCols = 15
    rt.Cells(rt.Rows.Count-1,0).text = "上海五金有限公司"
    rt.Cells(rt.Rows.Count-1,0).Style.Font = New Font("宋体", 18, FontStyle.Bold) '设置主标题字体
    '设置副标题------------------------------------------------2
    rt.Rows(rt.Rows.Count).Height = 12
    rt.Cells(rt.Rows.Count-1,0).SpanCols = 15
    rt.Cells(rt.Rows.Count-1,0).Style.Font = New Font("宋体", 16, FontStyle.Bold) '设置副标题字体
    rt.Rows(rt.Rows.Count-1).Style.Borders.All = New prt.LineDef("0mm", Color.white) '去掉网格线
    rt.Rows(rt.Rows.Count-1).Style.Borders.Bottom = New prt.LineDef("0.3mm", Color.Black) '去掉网格线
    rt.Cells(rt.Rows.Count-1,0).text = "订单"
    '设置各单元格的值及样式
    '----------------------------------------------------------3
    rt.Rows(rt.Rows.Count).Height = 9
    rt.Cells(rt.Rows.Count-1,0).Style.Font = New Font("宋体", 12, FontStyle.Bold)
    rt.Cells(rt.Rows.Count-1,0).SpanCols = 3
    rt.Cells(rt.Rows.Count-1,0).Text= "编号:" & CurRow("编号")
    rt.Cells(rt.Rows.Count-1,3).SpanCols = 2
    rt.Cells(rt.Rows.Count-1,3).Text= "客户:" & CurRow("客户")
    rt.Cells(rt.Rows.Count-1,5).SpanCols = 3
    rt.Cells(rt.Rows.Count-1,5).Text = "订单类别:" & CurRow("订单类别")
    '----------------------------------------------------------4
    rt.Cells(rt.Rows.Count-1,8).SpanCols = 4
    rt.Cells(rt.Rows.Count-1,8).Text = "制单日期:" & iif(CurRow.IsNull("制单日期"),"",CurRow("制单日期"))
    rt.Cells(rt.Rows.Count-1,12).SpanCols = 3
    rt.Cells(rt.Rows.Count-1,12).Text = "交货日期:" & iif(CurRow.IsNull("交货日期"),"",CurRow("交货日期"))
    '----------------------------------------------------------5
    rt.Rows(rt.Rows.Count).Height = 9
    rt.Cells(rt.Rows.Count-1,0).Style.Font = New Font("宋体", 12, FontStyle.Bold)
    rt.Cells(rt.Rows.Count-1,0).SpanCols = 3
    rt.Cells(rt.Rows.Count-1,0).Text= "业务员:"
    rt.Cells(rt.Rows.Count-1,3).SpanCols = 2
    rt.Cells(rt.Rows.Count-1,5).SpanCols = 7
    rt.Cells(rt.Rows.Count-1,12).SpanCols = 3
    rt.Cells(rt.Rows.Count-2,8).Spanrows = 2
    rt.Cells(rt.Rows.Count-2,12).Spanrows = 2
    
    '----------------------------------------------------------6
    rt.Rows(rt.Rows.Count).Height = 9
    rt.Cells(rt.Rows.Count-1,0).Style.Font = New Font("宋体", 12, FontStyle.Bold)
    rt.Cells(rt.Rows.Count-1,0).SpanCols = 3
    rt.Cells(rt.Rows.Count-1,0).Text= "订单类别:库存订单"
    rt.Cells(rt.Rows.Count-1,3).SpanCols = 4
    rt.Cells(rt.Rows.Count-1,7).SpanCols = 8
    '----------------------------------------------------------7
    rt.Rows(rt.Rows.Count).Height = 9
    rt.Cells(rt.Rows.Count-1,0).Style.Font = New Font("宋体", 12, FontStyle.Bold)
    Dim ColNames As String() = New String(){"编号","品名","数量","单位","规格","备注"}
    For c As Integer = 0 To ColNames.Length -1
        rt.Cells(rt.Rows.Count-1,c).Text= ColNames(c)
    Next
    rt.RowGroups(0,7).Header = prt.TableHeaderEnum.Page  '指定表头行
    rt.Rows(rt.Rows.Count).Height = 8
    rt.RowGroups(rt.Rows.Count-1,1).DataBinding.DataSource = BindTables("订单.订单明细") '将第四行绑定到订单明细表
    For c As Integer = 0 To ColNames.Length -1
        If tb.Cols(c).IsNumeric OrElse tb.Cols(c).IsDate Then '如果是数值或日期列
            rt.Cols(c).Style.TextAlignHorz = prt.AlignHorzEnum.Right '数据水平靠右
        End If
        rt.Cells(rt.Rows.Count-1,c).Text = "[Fields!" & ColNames(c) & ".Value]" '设置绑定表达式
    Next
    '设置表尾----------------------------------------------------8
    rt.Rows(rt.Rows.Count).Height = 6
    rt.Rows(rt.Rows.Count-1).Style.Borders.All = New prt.LineDef("0mm", Color.white) '去掉网格线
    rt.Rows(rt.Rows.Count-1).Style.Borders.Top = New prt.LineDef("0.3mm", Color.Black) '恢复上方网格线
    rt.Cells(rt.Rows.Count-1,1).Style.Borders.left = New prt.LineDef("0mm", Color.white)
    rt.Cells(rt.Rows.Count-1,0).Text= "备注:"
    rt.Cells(rt.Rows.Count-1,1).SpanCols = 14
    rt.Cells(rt.Rows.Count-1,1).Text= CurRow("备注")
    rt.Rows(rt.Rows.Count).Height = 6
    rt.Rows(rt.Rows.Count-1).Style.Borders.All = New prt.LineDef("0mm", Color.white) '去掉网格线
    rt.Cells(rt.Rows.Count-1,0).SpanCols = 15
    rt.Cells(rt.Rows.Count-1,0).Text = "第[PageNo]页,共[PageCount]页"
    rt.RowGroups(rt.Rows.Count-1,1).Style.TextAlignHorz = prt.AlignHorzEnum.Right '文本水平位置
    rt.RowGroups(rt.Rows.Count-2,2).Footer = prt.TableHeaderEnum.All '指定表尾行
    doc.Body.Children.Add(rt) '将表格对象加入到报表中
Next

Doc.Preview() '预览报表
[此贴子已经被作者于2014-1-4 11:07:57编辑过]

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


加好友 发短信 一级勋章
等级:超级版主 帖子:7237 积分:40614 威望:0 精华:16 注册:2008/8/31 23:23:00
  发帖心情 Post By:2014/1/4 13:29:00 [只看该作者]

很明显,循环应该嵌套在最外层:

 

For n As Integer = Tables("订单").TopRow To Tables("订单").BottomRow
    Dim doc As New PrintDoc '定义一个报表
    Dim Mtb As Table = Tables("订单")
    Dim tb As Table = Tables("订单.订单明细")
    Dim CurRow As Row = Tables("订单").rows(n) '获取当前行
    '设置打印纸张
    doc.PageSetting.PaperKind = 9  'A4
    'doc.PageSetting.Width = 210 '纸张宽度毫米
    'doc.PageSetting.Height = 290 '纸张高度毫米
    doc.PageSetting.Landscape = True '是否横向打印
    Doc.PageSetting.LeftMargin = 10 '设置左边距
    Doc.PageSetting.RightMargin = 10 '设置右边距
    Doc.PageSetting.TopMargin = 8 '设置上边距
    Doc.PageSetting.BottomMargin = 8 '设置下边距
    Dim rt As New prt.RenderTable() '定义一个表格对象
    '---------------------------------指定第一个表行数,列数,
    rt.Cols.Count = 15 '设置总列数
    '---------------------------------设置指定行的列宽,未指定的平分剩余宽度
    Dim CW As String = "20|12|12|25|20|15|30|15|15|15|15|10"
    Dim Cls As String() = CW.split("|")
    For i As Integer = 0 To Cls.Length-1
        rt.Cols(i).Width = Cls(i)
    Next
    '设置表格总体样式
    rt.Style.TextAlignHorz = prt.AlignHorzEnum.Center '文本水平居中
    rt.Style.TextAlignVert = prt.AlignVertEnum.Center '文本垂直居中
    rt.CellStyle.Spacing.All = 1 '单元格内容缩进1毫米
    rt.Style.GridLines.All = New prt.Linedef(0.3,Color.Black) '设置网格线
    rt.Style.Font = New Font("宋体", 12) '设置总体字体
    'rt.SplitVertBehavior = prt.SplitBehaviorEnum.Never '禁止被垂直分割
    rt.SplitHorzBehavior = prt.SplitBehaviorEnum.SplitIfNeeded '表格宽度超出页宽时,可以水平换页
    '设置主标题------------------------------------------------1
    rt.Rows(rt.Rows.Count).Height = 12
    rt.Rows(rt.Rows.Count-1).Style.Borders.All = New prt.LineDef("0mm", Color.white) '去掉网格线
    rt.Cells(rt.Rows.Count-1,0).SpanCols = 15
    rt.Cells(rt.Rows.Count-1,0).text = "上海五金有限公司"
    rt.Cells(rt.Rows.Count-1,0).Style.Font = New Font("宋体", 18, FontStyle.Bold) '设置主标题字体
    '设置副标题------------------------------------------------2
    rt.Rows(rt.Rows.Count).Height = 12
    rt.Cells(rt.Rows.Count-1,0).SpanCols = 15
    rt.Cells(rt.Rows.Count-1,0).Style.Font = New Font("宋体", 16, FontStyle.Bold) '设置副标题字体
    rt.Rows(rt.Rows.Count-1).Style.Borders.All = New prt.LineDef("0mm", Color.white) '去掉网格线
    rt.Rows(rt.Rows.Count-1).Style.Borders.Bottom = New prt.LineDef("0.3mm", Color.Black) '去掉网格线
    rt.Cells(rt.Rows.Count-1,0).text = "订单"
    '设置各单元格的值及样式
    '----------------------------------------------------------3
    rt.Rows(rt.Rows.Count).Height = 9
    rt.Cells(rt.Rows.Count-1,0).Style.Font = New Font("宋体", 12, FontStyle.Bold)
    rt.Cells(rt.Rows.Count-1,0).SpanCols = 3
    rt.Cells(rt.Rows.Count-1,0).Text= "编号:" & CurRow("编号")
    rt.Cells(rt.Rows.Count-1,3).SpanCols = 2
    rt.Cells(rt.Rows.Count-1,3).Text= "客户:" & CurRow("客户")
    rt.Cells(rt.Rows.Count-1,5).SpanCols = 3
    rt.Cells(rt.Rows.Count-1,5).Text = "订单类别:" & CurRow("订单类别")
    '----------------------------------------------------------4
    rt.Cells(rt.Rows.Count-1,8).SpanCols = 4
    rt.Cells(rt.Rows.Count-1,8).Text = "制单日期:" & iif(CurRow.IsNull("制单日期"),"",CurRow("制单日期"))
    rt.Cells(rt.Rows.Count-1,12).SpanCols = 3
    rt.Cells(rt.Rows.Count-1,12).Text = "交货日期:" & iif(CurRow.IsNull("交货日期"),"",CurRow("交货日期"))
    '----------------------------------------------------------5
    rt.Rows(rt.Rows.Count).Height = 9
    rt.Cells(rt.Rows.Count-1,0).Style.Font = New Font("宋体", 12, FontStyle.Bold)
    rt.Cells(rt.Rows.Count-1,0).SpanCols = 3
    rt.Cells(rt.Rows.Count-1,0).Text= "业务员:"
    rt.Cells(rt.Rows.Count-1,3).SpanCols = 2
    rt.Cells(rt.Rows.Count-1,5).SpanCols = 7
    rt.Cells(rt.Rows.Count-1,12).SpanCols = 3
    rt.Cells(rt.Rows.Count-2,8).Spanrows = 2
    rt.Cells(rt.Rows.Count-2,12).Spanrows = 2
   
    '----------------------------------------------------------6
    rt.Rows(rt.Rows.Count).Height = 9
    rt.Cells(rt.Rows.Count-1,0).Style.Font = New Font("宋体", 12, FontStyle.Bold)
    rt.Cells(rt.Rows.Count-1,0).SpanCols = 3
    rt.Cells(rt.Rows.Count-1,0).Text= "订单类别:库存订单"
    rt.Cells(rt.Rows.Count-1,3).SpanCols = 4
    rt.Cells(rt.Rows.Count-1,7).SpanCols = 8
    '----------------------------------------------------------7
    rt.Rows(rt.Rows.Count).Height = 9
    rt.Cells(rt.Rows.Count-1,0).Style.Font = New Font("宋体", 12, FontStyle.Bold)
    Dim ColNames As String() = New String(){"编号","品名","数量","单位","规格","备注"}
    For c As Integer = 0 To ColNames.Length -1
        rt.Cells(rt.Rows.Count-1,c).Text= ColNames(c)
    Next
    rt.RowGroups(0,7).Header = prt.TableHeaderEnum.Page  '指定表头行
    rt.Rows(rt.Rows.Count).Height = 8
    rt.RowGroups(rt.Rows.Count-1,1).DataBinding.DataSource = BindTables("订单.订单明细") '将第四行绑定到订单明细表
    For c As Integer = 0 To ColNames.Length -1
        If tb.Cols(c).IsNumeric OrElse tb.Cols(c).IsDate Then '如果是数值或日期列
            rt.Cols(c).Style.TextAlignHorz = prt.AlignHorzEnum.Right '数据水平靠右
        End If
        rt.Cells(rt.Rows.Count-1,c).Text = "[Fields!" & ColNames(c) & ".Value]" '设置绑定表达式
    Next
    '设置表尾----------------------------------------------------8
    rt.Rows(rt.Rows.Count).Height = 6
    rt.Rows(rt.Rows.Count-1).Style.Borders.All = New prt.LineDef("0mm", Color.white) '去掉网格线
    rt.Rows(rt.Rows.Count-1).Style.Borders.Top = New prt.LineDef("0.3mm", Color.Black) '恢复上方网格线
    rt.Cells(rt.Rows.Count-1,1).Style.Borders.left = New prt.LineDef("0mm", Color.white)
    rt.Cells(rt.Rows.Count-1,0).Text= "备注:"
    rt.Cells(rt.Rows.Count-1,1).SpanCols = 14
    rt.Cells(rt.Rows.Count-1,1).Text= CurRow("备注")
    rt.Rows(rt.Rows.Count).Height = 6
    rt.Rows(rt.Rows.Count-1).Style.Borders.All = New prt.LineDef("0mm", Color.white) '去掉网格线
    rt.Cells(rt.Rows.Count-1,0).SpanCols = 15
    rt.Cells(rt.Rows.Count-1,0).Text = "第[PageNo]页,共[PageCount]页"
    rt.RowGroups(rt.Rows.Count-1,1).Style.TextAlignHorz = prt.AlignHorzEnum.Right '文本水平位置
    rt.RowGroups(rt.Rows.Count-2,2).Footer = prt.TableHeaderEnum.All '指定表尾行
    doc.Body.Children.Add(rt) '将表格对象加入到报表中
    Doc.Preview() '预览报表
Next


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


加好友 发短信
等级:四尾狐 帖子:976 积分:8527 威望:0 精华:0 注册:2012/2/9 16:35:00
  发帖心情 Post By:2014/1/4 13:58:00 [只看该作者]

那样的话选择多行后会重复预览多次,正常应该是多行的数据一次打开后全部按页显示出来。
原来我那种写法主表行的数据是显示正确的,只是明细表没有按主表行筛选出为,不知道绑定数据表是不是没有这种功能,即下面红色的能否根据主表行的订单编号等加入筛选

  rt.RowGroups(rt.Rows.Count-1,1).DataBinding.DataSource = BindTables("订单.订单明细") '将第四行绑定到订单明细表
    For c As Integer = 0 To ColNames.Length -1
        If tb.Cols(c).IsNumeric OrElse tb.Cols(c).IsDate Then '如果是数值或日期列
            rt.Cols(c).Style.TextAlignHorz = prt.AlignHorzEnum.Right '数据水平靠右
        End If
        rt.Cells(rt.Rows.Count-1,c).Text = "[Fields!" & ColNames(c) & ".Value]" '设置绑定表达式
    Next



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


加好友 发短信 一级勋章
等级:超级版主 帖子:7237 积分:40614 威望:0 精华:16 注册:2008/8/31 23:23:00
  发帖心情 Post By:2014/1/4 15:15:00 [只看该作者]

哦,那要改代码,等我有了时间看看!


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


加好友 发短信
等级:四尾狐 帖子:976 积分:8527 威望:0 精华:0 注册:2012/2/9 16:35:00
  发帖心情 Post By:2014/1/4 21:01:00 [只看该作者]

好的,谢谢!

 回到顶部
总数 37 上一页 1 2 3 4