Dim doc As New PrintDoc '定义一个报表
Doc.Stacking = prt.StackingRulesEnum.InlineLeftToRight
Dim ra As New prt.RenderArea
Dim rt As prt.RenderText
Dim rt1 As prt.RenderText
ra.Width = 90 '设置标签宽度
ra.Height = 54
ra.SplitHorzBehavior = prt.SplitBehaviorEnum.Never '禁止水平分割
ra.SplitVertBehavior = prt.SplitBehaviorEnum.Never '禁止垂直分割
ra.Style.Spacing.Right = 0 '设置标签之间的所有和上下间隔为2毫米
ra.Style.Spacing.Bottom = 0
ra.Style.Padding.All = 3 ' 标签内容距离边框为1毫米
ra.Style.Borders.All = New prt.Linedef(0.3, Color.Red) '设置边框
ra.DataBinding.DataSource = BindTables("报名表") '将容器绑定到员工表
Doc.Body.ChildRen.Add(ra) '将容器加入到报表中
Dim r As prt.RenderText
r = New prt.RenderText
r.Style.Spacing.Bottom = 2
r.text="2013年武汉市中小学航空航天模型竞赛"
r.Style.TextAlignHorz = prt.AlignHorzEnum.Center
ra.Children.Add(r) '添加到容器中
r = new prt.RenderText
r.Style.Spacing.Bottom = 3
r.text="参 赛 证"
r.Style.Font = New Font("楷体", 16, FontStyle.Bold)
r.Style.TextAlignHorz = prt.AlignHorzEnum.Center
ra.Children.Add(r)
rt = New prt.RenderText
rt.Style.Spacing.Bottom = 1
rt.Text = "编号:[Fields!编号.Value]"
ra.Children.Add(rt) '添加到容器中
rt = New prt.RenderText
rt.Style.Spacing.Bottom = 1
rt.Text = "姓名:[Fields!姓名.Value]"
ra.Children.Add(rt) '添加到容器中
rt = New prt.RenderText
rt.Style.Spacing.Bottom = 1
rt.Text = "学校:[Fields!学校.Value]"
ra.Children.Add(rt) '添加到容器中
rt = New prt.RenderText
rt.Style.Spacing.Bottom = 1
rt.Text = "参赛项目:[Fields!参赛项目.Value]"
ra.Children.Add(rt) '添加到容器中
rt = New prt.RenderText
rt.Style.Spacing.Bottom = 1
rt.Text = "组别:[Fields!组别.Value]"
ra.Children.Add(rt) '添加到容器中
rt = New prt.RenderText
rt.Style.Spacing.Bottom = 1
rt.Text = "场地:[Fields!场地.Value]"
ra.Children.Add(rt) '添加到容器中
Doc.PageSetting.LeftMargin = 15 '设置左边距
Doc.PageSetting.RightMargin = 15 '设置右边距
Doc.PageSetting.TopMargin = 13 '设置上边距
Doc.PageSetting.BottomMargin = 13 '设置下边距
Doc.Preview()
以上代码执行正常。
现在的问题是:“组别”与“场地”只需打印一个出来,“组别"列的值为空打印“场地”
“场地”列的值为空打印“组别”。学习了一段代码后,将原代码改为
Dim doc As New PrintDoc '定义一个报表
Doc.Stacking = prt.StackingRulesEnum.InlineLeftToRight
Dim ra As New prt.RenderArea
Dim rt As prt.RenderText
Dim rt1 As prt.RenderText
ra.Width = 90 '设置标签宽度
ra.Height = 54
ra.SplitHorzBehavior = prt.SplitBehaviorEnum.Never '禁止水平分割
ra.SplitVertBehavior = prt.SplitBehaviorEnum.Never '禁止垂直分割
ra.Style.Spacing.Right = 0 '设置标签之间的所有和上下间隔为2毫米
ra.Style.Spacing.Bottom = 0
ra.Style.Padding.All = 3 ' 标签内容距离边框为1毫米
ra.Style.Borders.All = New prt.Linedef(0.3, Color.Red) '设置边框
ra.DataBinding.DataSource = BindTables("报名表") '将容器绑定到员工表
Doc.Body.ChildRen.Add(ra) '将容器加入到报表中
Dim r As prt.RenderText
r = New prt.RenderText
r.Style.Spacing.Bottom = 2
r.text="2013年武汉市中小学航空航天模型竞赛"
r.Style.TextAlignHorz = prt.AlignHorzEnum.Center
ra.Children.Add(r) '添加到容器中
r = new prt.RenderText
r.Style.Spacing.Bottom = 3
r.text="参 赛 证"
r.Style.Font = New Font("楷体", 16, FontStyle.Bold)
r.Style.TextAlignHorz = prt.AlignHorzEnum.Center
ra.Children.Add(r)
rt = New prt.RenderText
rt.Style.Spacing.Bottom = 1
rt.Text = "编号:[Fields!编号.Value]"
ra.Children.Add(rt) '添加到容器中
rt = New prt.RenderText
rt.Style.Spacing.Bottom = 1
rt.Text = "姓名:[Fields!姓名.Value]"
ra.Children.Add(rt) '添加到容器中
rt = New prt.RenderText
rt.Style.Spacing.Bottom = 1
rt.Text = "学校:[Fields!学校.Value]"
ra.Children.Add(rt) '添加到容器中
rt = New prt.RenderText
rt.Style.Spacing.Bottom = 1
rt.Text = "参赛项目:[Fields!参赛项目.Value]"
ra.Children.Add(rt) '添加到容器中
If CurrentTable.Current. Is not Null("组别") Then
rt = New prt.RenderText
rt.Style.Spacing.Bottom = 1
rt.Text = "组别:[Fields!组别.Value]"
ra.Children.Add(rt) '添加到容器中
End If
If CurrentTable.Current. Is not Null("场地") Then
rt = New prt.RenderText
rt.Style.Spacing.Bottom = 1
rt.Text = "场地:[Fields!场地.Value]"
ra.Children.Add(rt) '添加到容器中
End If
Doc.PageSetting.LeftMargin = 15 '设置左边距
Doc.PageSetting.RightMargin = 15 '设置右边距
Doc.PageSetting.TopMargin = 13 '设置上边距
Doc.PageSetting.BottomMargin = 13 '设置下边距
Doc.Preview()
但提示出错。去掉“Is not Null”中的not,可以执行,但是不能满足要求。与上面没有修改的代码执行结果一样。
请专家指点!!!