以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 专业报表问题 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=83525) |
-- 作者:happyft -- 发布时间:2016/4/11 18:32:00 -- 专业报表问题 如上图,生产单的明细表有两个一个是物料明细,一个是工序明细,打印时要求在一行中左边显示物料明细的内容,右边显示工序明细的内容 当只有一个明细表是觉得很简单:用下面的代码就可以 ‘---------------------------------------- rt = New prt.RenderTable() \'定义一个表格对象 rt.Rows(rt.Rows.Count).Height = 9 \'新增一行 rt.Cells(rt.Rows.Count-1,0).SpanCols = 2 rt.Cells(rt.Rows.Count-1,0).Text = "产品代号" rt.Cells(rt.Rows.Count-1,1).SpanCols = 3 rt.Cells(rt.Rows.Count-1,1).Text = CurRow("产品编码") rt.Cells(rt.Rows.Count-1,2).Text = "产品规格" rt.Cells(rt.Rows.Count-1,3).Text = CurRow("规格") rt.Cells(rt.Rows.Count-1,4).SpanCols = 2 rt.Cells(rt.Rows.Count-1,4).Text = "下单日期" rt.Cells(rt.Rows.Count-1,5).SpanCols = 2 rt.Cells(rt.Rows.Count-1,5).Text = CurRow("下单日期") rt.Rows(rt.Rows.Count).Height = 9 \'新增一行 rt.Cells(rt.Rows.Count-1,0).SpanCols = 2 rt.Cells(rt.Rows.Count-1,0).Text = "产品名称" rt.Cells(rt.Rows.Count-1,1).SpanCols = 3 rt.Cells(rt.Rows.Count-1,1).Text = CurRow("品名") rt.Cells(rt.Rows.Count-1,2).Text = "生产数量" rt.Cells(rt.Rows.Count-1,3).Text = CurRow("生产数量") rt.Cells(rt.Rows.Count-1,4).SpanCols = 2 rt.Cells(rt.Rows.Count-1,4).Text = "完成日期" rt.Cells(rt.Rows.Count-1,5).SpanCols = 2 rt.Cells(rt.Rows.Count-1,5).Text = CurRow("计划结束") rt.Rows(rt.Rows.Count).Height = 9 \'新增一行 rt.Cells(rt.Rows.Count-1,0).SpanCols = 6 rt.Cells(rt.Rows.Count-1,0).Text = "物料明细" rt.Cells(rt.Rows.Count-1,1).SpanCols = 6 rt.Cells(rt.Rows.Count-1,1).Text = "工序明细" rt.Rows(rt.Rows.Count).Height = "auto" \'新增一行 rt.Rows(rt.Rows.Count-1).Style.Font = New Font("宋体",9) \'设置字体 rt.Rows(rt.Rows.Count-1).Style.TextAlignHorz = prt.AlignHorzEnum.Center \'文本水平居中 Dim nms As String() = {"使用工序","材料代号","规格","单位","需求数量","工序号","工序名称","模号","机台吨位","加工方式","生产车间"} \'明细表标题列 For c As Integer = 0 To nms.Length -1 rt.Cells(rt.Rows.Count-1,c).Text = nms(c) Next rt.RowGroups(0,1).Header = prt.TableHeaderEnum.Page \'指定表头行 Dim ColNames As String() = {"使用工序","物料编码","规格","计量单位","需求数量","工序号","工序名称","模号","机台吨位","加工方式","生产车间"} \'明细表数据列 Dim drs As List(Of DataRow) drs = DataTables("生产单_物料明细").Select("生产单号 = \'" & CurRow("生产单号") & "\'") If drs.Count > 0 Then \'如果有值 For i As Integer = 0 To drs.Count-1 rt.Rows(rt.Rows.Count).Height = rh \'新增一行 For c As Integer = 0 To ColNames.Length -1 If c < 5 Then \'左边五列来自生产物料明细 rt.cells(rt.Rows.Count-1,c).text = dr(i)(ColNames(c)) Else rt.cells(rt.Rows.Count-1,c).text = dr(i)(ColNames(c)) End If Next Next End If \'----------------------------------------------------------3 上面红色部份不知道怎么写了,因为两个明细表的行数可能不一样,比如,只有2个工序,但可能用到4种物料;是否必须按多行的那个行数来计算? 前五列是从物料明细取数,后五列又是从工序明细取数,要怎么写代码? 谢谢! |
-- 作者:大红袍 -- 发布时间:2016/4/11 19:29:00 -- 不是可以在单元格里面插入对象的吗?
分别生成两个新的表格,然后插入到两个单元格即可,如 rt.Cells(1, 2).RenderObject = 表格对象rt2 |
-- 作者:HappyFt -- 发布时间:2016/4/11 20:05:00 -- 那如果表的行数超出了一页以上怎么办呢?比如有20行,但每页只能打印6行。 |
-- 作者:大红袍 -- 发布时间:2016/4/11 20:07:00 -- 为什么要理会行数,直接把表弄出来,它不是自动排好的了吗? |
-- 作者:HappyFt -- 发布时间:2016/4/11 22:43:00 -- 代码如下:中间红色那段写法好象不对,生成的报表不正确 \'\'\' 省略上面部份生成表头的代码 \'1--------------------------------定义主副标题----------------------------------1 Dim ra As New prt.RenderArea \'定义一个容器 \'---定义主标题 \'2-------------------------------定义表格抬头-------------------------------------- Dim rt As New prt.RenderTable() \'定义一个表格对象 \'指定总列数及各列宽,未指定的最后一列平分剩余宽度(12列) CW = dr8("Bodycw") \'"" Cls = CW.split("|") rt.Cols.Count = Cls.Length + 1 \'设置总列数 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.2,Color.Black) \'设置网格线 rt.Style.Font = New Font("宋体", prt_tbfontsize) \'设置总体字体 \'rt.SplitVertBehavior = prt.SplitBehaviorEnum.SplitIfNeeded \'禁止被垂直分割 \'rt.SplitHorzBehavior = prt.SplitBehaviorEnum.SplitIfNeeded \'表格宽度超出页宽时,可以水平换页 \'---设置明细表标题列--------- \' rt.Style.Spacing.Bottom = prt_Upspacing \'和下一个对象的距离(毫米) \' ra.Children.Add(rt) \'将文本对象加入到容器ra中 \'------------------设置以上部份作为页眉------------------------ \' doc.PageHeader = ra \'(页眉本身就是报表的一部份,不能再用语句加入到报表中会出错) \'2----------------------------------------定义明细表表体----------------------------------2 \'ra = New prt.RenderArea \'定义一个容器 rt = New prt.RenderTable() \'定义一个表格对象 rt.Rows(rt.Rows.Count).Height = 9 \'新增一行 rt.Cells(rt.Rows.Count-1,0).SpanCols = 6 rt.Cells(rt.Rows.Count-1,0).Text = "物料明细" rt.Cells(rt.Rows.Count-1,1).SpanCols = 6 rt.Cells(rt.Rows.Count-1,1).Text = "工序明细" rt.Rows(rt.Rows.Count).Height = "auto" \'新增一行 rt.Rows(rt.Rows.Count-1).Style.Font = New Font("宋体",9) \'设置字体 rt.Rows(rt.Rows.Count-1).Style.TextAlignHorz = prt.AlignHorzEnum.Center \'文本水平居中 Dim nms As String() = {"使用工序","材料代号","规格","单位","需求数量","工序号","工序名称","模号","机台吨位","加工方式","生产车间"} \'明细表标题列 For c As Integer = 0 To nms.Length -1 rt.Cells(rt.Rows.Count-1,c).Text = nms(c) Next rt.RowGroups(0,1).Header = prt.TableHeaderEnum.Page \'指定表头行(因为是逐列增加的,所以行组只能用一行) ra.Children.Add(rt) \'将文本对象加入到容器ra中 \'--------------------------生成物料明细表-------------------------------- Dim rt2 As New prt.RenderTable() \'定义一个表格对象 rt2.Style.Spacing.Top = 1 \'和上一个对象的距离(毫米) \'指定总列数及各列宽,未指定的平分剩余宽度 CW = "8|16|16|8|16" Cls = CW.split("|") rt2.Cols.Count = Cls.Length \'设置总列数 For i As Integer = 0 To Cls.Length-1 rt2.Cols(i).Width = Cls(i) Next \'设置表格总体样式-------------------------------------------0 rt2.Style.TextAlignHorz = prt.AlignHorzEnum.Center \'文本水平居中 rt2.Style.TextAlignVert = prt.AlignVertEnum.Center \'文本垂直居中 rt2.CellStyle.Spacing.All = 1 \'单元格内容缩进1毫米 rt2.Style.GridLines.All = New prt.Linedef(0.2,Color.Black) \'设置网格线 rt2.Style.Font = New Font("宋体", 12) \'设置总体字体 rt2.Style.TextAlignHorz = prt.AlignHorzEnum.Center \'文本位置 \'rt2.SplitVertBehavior = prt.SplitBehaviorEnum.Never \'禁止被垂直分割 rt2.SplitVertBehavior = prt.SplitBehaviorEnum.SplitIfNeeded \'禁止被垂直分割 \'rt2.SplitHorzBehavior = prt.SplitBehaviorEnum.SplitIfNeeded \'表格宽度超出页宽时,可以水平换页 \'-----------------------------------------------------------1 Dim ColNames As String() = {"使用工序","物料编码","规格","计量单位","需求数量"} \'明细表数据列 Dim drs As List(Of DataRow) drs = DataTables("生产单_物料明细").Select("生产单号 = \'" & CurRow("生产单号") & "\'") If drs.Count > 0 Then \'如果有值 For i As Integer = 0 To drs.Count-1 For c As Integer = 0 To ColNames.Length -1 rt2.cells(i,c).text = drs(i)(ColNames(c)) Next Next End If \'--------------------------生成工序明细表-------------------------------- Dim rt1 As New prt.RenderTable() \'定义一个表格对象 \'指定总列数及各列宽,未指定的平分剩余宽度 CW = "8|16|16|16|16|20" Cls = CW.split("|") rt1.Cols.Count = Cls.Length \'设置总列数 For i As Integer = 0 To Cls.Length-1 rt1.Cols(i).Width = Cls(i) Next \'设置表格总体样式-------------------------------------------0 rt1.Style.TextAlignHorz = prt.AlignHorzEnum.Center \'文本水平居中 rt1.Style.TextAlignVert = prt.AlignVertEnum.Center \'文本垂直居中 rt1.CellStyle.Spacing.All = 1 \'单元格内容缩进1毫米 rt1.Style.GridLines.All = New prt.Linedef(0.2,Color.Black) \'设置网格线 rt1.Style.Font = New Font("宋体", 12) \'设置总体字体 rt1.Style.TextAlignHorz = prt.AlignHorzEnum.Center \'文本位置 \'rt1.SplitVertBehavior = prt.SplitBehaviorEnum.Never \'禁止被垂直分割 rt1.SplitVertBehavior = prt.SplitBehaviorEnum.SplitIfNeeded \'禁止被垂直分割 \'rt1.SplitHorzBehavior = prt.SplitBehaviorEnum.SplitIfNeeded \'表格宽度超出页宽时,可以水平换页 \'-----------------------------------------------------------1 Dim ColNames2 As String() = {"工序号","工序名称","设备名称","模具编号","加工方式","生产车间"} \'明细表数据列 drs = DataTables("生产单_明细").Select("生产单号 = \'" & CurRow("生产单号") & "\'") If drs.Count > 0 Then \'如果有值 For i As Integer = 0 To drs.Count-1 For c As Integer = 0 To ColNames2.Length -1 rt1.cells((i),c).text = drs(i)(ColNames2(c)) Next Next End If rt = New prt.RenderTable() \'定义一个表格对象 \'设置表格总体样式-------------------------------------------0 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.2,Color.Black) \'设置网格线 rt.Style.Font = New Font("宋体", 12) \'设置总体字体 rt.Style.TextAlignHorz = prt.AlignHorzEnum.Center \'文本位置 \'rt.SplitVertBehavior = prt.SplitBehaviorEnum.Never \'禁止被垂直分割 rt.SplitVertBehavior = prt.SplitBehaviorEnum.SplitIfNeeded \'禁止被垂直分割 \'rt.SplitHorzBehavior = prt.SplitBehaviorEnum.SplitIfNeeded \'表格宽度超出页宽时,可以水平换页 rt.Rows(rt.Rows.Count).Height = 9 \'新增一行 rt.Cells(rt.Rows.Count-1,0).SpanCols = 6 rt.Cells(rt.Rows.Count-1,1).SpanCols = 6 rt.Cells(rt.Rows.Count-1,0).RenderObject = rt2 rt.Cells(rt.Rows.Count-1,1).RenderObject = rt1 doc.Body.Children.Add(rt) \'将表格对象加入到报表中 \'-------定义表格下方签名栏 rx = New prt.RenderText \'定义一个文本对象 rx.Style.Spacing.Top = 2 \'和上一个对象的距离(毫米) rx.Text = "批准: 审核: 制表:" \'rx.Style.LineSpacing = prt_Bottomlinespacing \'设置双倍行距 \' rx.Style.TextAlignHorz = prt.AlignHorzEnum.Center \'水平居中 rx.Style.Font = New Font("宋体", prt_Bottomfontsize) \'设置字体 \'rx.Style.Spacing.Bottom = 8 \'和下一个对象的距离(毫米) ra.Children.Add(rx) \'将文本对象加入到容器ra中 doc.Body.Children.Add(ra) \'将表格对象加入到报表中 Doc.Preview() \'预览报表 End If
|
-- 作者:大红袍 -- 发布时间:2016/4/11 22:45:00 -- 你还是上传实例,直接说要做的效果吧。 |
-- 作者:HappyFt -- 发布时间:2016/4/12 0:15:00 -- |
-- 作者:Hyphen -- 发布时间:2016/4/12 8:39:00 -- 麻烦上传有数据测试的例子 |
-- 作者:大红袍 -- 发布时间:2016/4/12 9:23:00 -- 1、行高的问题,你列的内容不同,而宽度固定以后,高度肯定不同的啊,这个没办法;
2、指定标题行 http://www.foxtable.com/help/topics/2735.htm
|