下面的代码想实现出库单一式两联,但总是编译出错,不知哪出错了,请老师给看看吧。另如何打印出出库单上的物品的总价呢?
Dim doc As New PrintDoc '定义一个新报表
Dim rt As New prt.RenderTable '定义一个新表格
Dim rs As New prt.RenderText() '定义一个文本对象
Dim rs2 As New prt.RenderText()
Dim rt1 As New prt.RenderTable() '定义一个表格对象
doc.PageSetting.PaperKind = 9 '纸张A4
Doc.PageSetting.LeftMargin = 20 '设置左边距
Doc.PageSetting.RightMargin = 20 '设置右边距
Doc.PageSetting.TopMargin = 20 '设置上边距
Doc.PageSetting.BottomMargin = 20 '设置下边距
rt.Style.Spacing.Top = 1 '表格和前面对象的垂直间隔为1毫米
rt.Style.Spacing.Bottom = 1 '表和和后续对象的垂直间隔为1毫米
rs.Text = "青铜峡市铝业学校入库单" '设置文本对象的内容
rs.Style.Font = New Font("宋体", 16 , FontStyle.Bold) '设置文本对象的字体
rs.Style.TextAlignHorz = prt.AlignHorzEnum.Center '文本内容水平居中
doc.Body.Children.Add(rs) '将文本对象加入到表格中
doc.Body.Children.Add(rt1) '将表格对象加入到报表中
rs2 = New prt.RenderText() '再次定义一个文本对象
rs2.Text = "第一联:报账凭证"
doc.Body.Children.Add(rs2) '将文本对象加入到表格中
Dim tb As Table = Tables("打印入库单_table1") '.Cols("办理入库") = 'True'
Dim Colnames As String() = {"物品名称","规格型号","单位","采购数量","采购单价","采购总价","供货单位"}
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.Cells(0,c).Style.TextAlignHorz = prt.AlignHorzEnum.Center '标题内容水平居中
rt.Cols(c).Width = tb.Cols(colnames(c)).PrintWidth '列宽等于实际列宽
' If tb.Cols(colnames(c)).IsNumeric Then '如果是数值或日期列
rt.Cols(c).Style.TextAlignHorz = prt.AlignHorzEnum.Center '数据水平靠右
' End If
Dim i As Integer = 1
' For r As Integer = tb.TopPosition To tb.BottomPosition '开始填入该列内容
For r As Integer = 0 To tb.Rows.Count -1
If tb.rows(r)("办理入库") = True Then
rt.Cells(i, c).Text = tb.Rows(r)(colnames(c))
i=i+1
End If
Next
Next
rt.Style.Gridlines.All = New prt.Linedef(Color.Gray) '灰色网格线
rt.CellStyle.Spacing.All = 0.5 '单元格内距设为0.5毫米
rt.Rows(0).Style.TextAlignHorz = prt.AlignHorzEnum.Center '第一行内容水平居中
rt.RowGroups(0,1).Header = prt.TableHeaderEnum.All '利用行组,将第一行设为表头
doc.Body.Children.Add(rt) '将表格加入到报表
Dim doc1 As New PrintDoc '定义一个新报表
Dim rt1 As New prt.RenderTable '定义一个新表格
Dim rs1 As New prt.RenderText() '定义一个文本对象
Dim rs3 As New prt.RenderText()
Dim rt3 As New prt.RenderTable() '定义一个表格对象
rt1.Style.Spacing.Top = 1 '表格和前面对象的垂直间隔为1毫米
rt1.Style.Spacing.Bottom = 1 '表和和后续对象的垂直间隔为1毫米
rs1.Text = "青铜峡市铝业学校入库单" '设置文本对象的内容
rs1.Style.Font = New Font("宋体", 16 , FontStyle.Bold) '设置文本对象的字体
rs1.Style.TextAlignHorz = prt.AlignHorzEnum.Center '文本内容水平居中
doc1.Body.Children.Add(rs1) '将文本对象加入到表格中
doc1.Body.Children.Add(rt3) '将表格对象加入到报表中
rs3 = New prt.RenderText() '再次定义一个文本对象
rs3.Text = "第二联:存根"
doc1.Body.Children.Add(rs3) '将文本对象加入到表格中
Dim tb1 As Table = Tables("打印入库单_table1") '.Cols("办理入库") = 'True'
Dim Colnames As String() = {"物品名称","规格型号","单位","采购数量","采购单价","采购总价","供货单位"}
rt1.Width = "Auto" '表格宽度为自动,也就是等于各列设置宽度之和
'rt.SplitHorzBehavior = prt.SplitBehaviorEnum.SplitIfNeeded '表格宽度超出页宽时,可以水平换页
rt1.Style.Font = tb1.Font
For c1 As Integer = 0 To Colnames.length -1 '逐列设置和填入内容
rt1.Cells(0,c1).Text = colnames(c1) '列名作为标题
rt1.Cells(0,c1).Style.TextAlignHorz = prt.AlignHorzEnum.Center '标题内容水平居中
rt1.Cols(c1).Width = tb1.Cols(colnames(c1)).PrintWidth '列宽等于实际列宽
' If tb.Cols(colnames(c)).IsNumeric Then '如果是数值或日期列
rt1.Cols(c1).Style.TextAlignHorz = prt.AlignHorzEnum.Center '数据水平靠右
' End If
Dim i1 As Integer = 1
' For r As Integer = tb.TopPosition To tb.BottomPosition '开始填入该列内容
For r1 As Integer = 0 To tb.Rows.Count -1
If tb1.rows(r1)("办理入库") = True Then
rt1.Cells(i1, c1).Text = tb.Rows(r1)(colnames(c1))
i1=i1+1
End If
Next
Next
rt1.Style.Gridlines.All = New prt.Linedef(Color.Gray) '灰色网格线
rt1.CellStyle.Spacing.All = 0.5 '单元格内距设为0.5毫米
rt1.Rows(0).Style.TextAlignHorz = prt.AlignHorzEnum.Center '第一行内容水平居中
rt1.RowGroups(0,10).Header = prt.TableHeaderEnum.All '利用行组,将第一行设为表头
doc1.Body.Children.Add(rt1) '将表格加入到报表
doc.Preview()