想打印如下格式的报表
目录名
分类名
标题
(项目分类 & 内容)段落
如文件所列的数据格式
设计如下代码:
Dim doc As New PrintDoc '定义报表
Dim ra As New prt.RenderArea '定义一个容器
Dim rpar As New prt.RenderParagraph() '定义一个段落
Dim tb as Table = CurrentTable
For r As integer = 0 To tb.Rows.Count -1 '从上而下排版内容
For c As Integer = 0 To tb.Cols.Count -1 '从左到右排版内容
If r > 0 AndAlso tb(r,c) <> tb(r - 1,c) AndAlso c = 0 Then
Dim rt As New prt.RenderText '定义第一列文本
rt.Text = Chr(13) & tb(r,c) & Chr(13)
ra.Children.Add(rt)
ElseIf r > 0 AndAlso tb(r,c) <> tb(r-1,c) AndAlso c = 1 Then
Dim rt As New prt.RenderText '定义第二列文本
rt.Text = Chr(13) & tb(r,c) & Chr(13)
ra.Children.Add(rt)
ElseIf r > 0 AndAlso tb(r,c) <> tb(r-1,c) AndAlso c = 2 Then
Dim rt As New prt.RenderText '定义第三列文本
rt.Text = Chr(13) & tb(r,c) & Chr(13)
ra.Children.Add(rt)
ra.Children.Add(rpar)
Dim rpar As New prt.RenderParagraph() '定义一个段落
ElseIf c = 3 Then
rpar.Content.AddText(tb(r,c),Color.DarkBlue, prt.TextPositionEnum.Superscript)
ElseIf c = 4 Then
rpar.Content.AddText(tb(r,c),Color.Red)
End If
Next
Next
doc.Body.Children.Add(ra)
Doc.preview()
但运行报错:
1.由于目录需要居中,所以选用prt.RenderArea容器来装载所有数据
2.由于段落需要首尾衔接,所以选用prt.RenderParagraph()类型
由于一个段落完成后,要重新定义新的段落(RenderParagraph()类型),不知道如何设置.
请大家看看是什么地方出了问题?
原来定义集合类型数据类型有这么2种语法
Dim Names As New List of(String)
Dim Names As List of(String)
不行,还是错误,我已经使用RenderText类型实现了段落排版.就是在段落中不能实现上标和正常字体两种设置.
Dim doc As New PrintDoc
Dim ra As New prt.RenderArea
Dim s As String = ""
ra.Stacking = prt.StackingRulesEnum.InlineLeftToRight
Dim tb as Table = CurrentTable
For r As integer = 0 To tb.Rows.Count -1 '从上而下排版内容
For c As Integer = 0 To tb.Cols.Count -1 '从左到右排版内容
If r > 0 AndAlso tb(r,c) <> tb(r - 1,c) AndAlso c = 0 OrElse r = 0 AndAlso c = 0 Then
Dim rt As New prt.RenderText '定义第一列文本
rt.Text = Chr(13) & tb(r,c) & Chr(13)
rt.Style.TextColor = Color.DarkGreen
rt.Style.Borders.Bottom = New prt.Linedef(Color.Green) '设置底边框
rt.Style.TextAlignHorz = prt.AlignHorzEnum.Center '水平居中
rt.Style.Font = New Font("黑体", 16, FontStyle.Bold) '设置字体
ra.Children.Add(rt)
ElseIf r > 0 AndAlso tb(r,c) <> tb(r-1,c) AndAlso c = 1 OrElse r = 0 AndAlso c = 1 Then
Dim rt As New prt.RenderText '定义第二列文本
rt.Text = Chr(13) & tb(r,c) & Chr(13)
rt.Style.TextColor = Color.Red '字符颜色设为红色
rt.Style.TextAlignHorz = prt.AlignHorzEnum.Center '水平居中
rt.Style.Font = New Font("楷体", 14, FontStyle.Bold) '设置字体
ra.Children.Add(rt)
ElseIf r > 0 AndAlso tb(r,c) <> tb(r-1,c) AndAlso c = 2 OrElse r = 0 AndAlso c = 2 Then
Dim rt As New prt.RenderText '定义第三列文本
rt.Text = Chr(13) & tb(r,c) & Chr(13)
rt.Style.TextColor = Color.DarkBlue '字符颜色设为红色
ra.Children.Add(rt)
Dim rt1 As New prt.RenderText '1
rt1.Text = s
rt1.Style.TextColor = Color.Black
rt1.Style.TextIndent = 9 '首行缩进9毫米
rt.Style.Font = New Font("楷体", 12, FontStyle.Regular) '设置字体
ra.Children.Add(rt1)
s = ""
ElseIf c = 3 Then
s = s & ""
ElseIf c = 4 Then
s = s & tb(r,c)
End If
Next
Next
doc.Body.Children.Add(ra)
Doc.preview()此主题相关图片如下:error.jpg