代码如下:中间红色那段写法好象不对,生成的报表不正确
此主题相关图片如下:qq截图20160411223858.png
'''
省略上面部份生成表头的代码
'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