以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]专业报表设计代码问题  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=5566)

--  作者:ssqq
--  发布时间:2009/12/20 2:20:00
--  [求助]专业报表设计代码问题
想打印如下格式的报表

           目录名
分类名
标题
(项目分类 & 内容)段落
如文件所列的数据格式
设计如下代码:
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()类型),不知道如何设置.
请大家看看是什么地方出了问题?

--  作者:ssqq
--  发布时间:2009/12/20 2:25:00
--  
上传附件
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:帮助文件打印.table


图片点击可在新窗口打开查看此主题相关图片如下:error.jpg
图片点击可在新窗口打开查看

--  作者:ssqq
--  发布时间:2009/12/20 15:04:00
--  
这个问题的跟本在于如何动态定义集合的名称.
Dim Names As New List(Of String)
如何用代码定义Names1,Names2,Names3.......等集合

就类似下面的代码定义
Dim t As String = "abc"
Dim s As Integer = 0
Dim Sum As String = t & s
Dim i As Integer
For i = 1 to 100
    s = s + 1
    Sum = t & s
Output.Show(Sum)
Next

--  作者:狐狸爸爸
--  发布时间:2009/12/21 9:17:00
--  
Dim doc As New PrintDoc \'定义报表
Dim ra As New prt.RenderArea \'定义一个容器
Dim rpar As  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 \'从左到右排版内容
       rpar = New prt.RenderParagraph() \'定义一个段落
       。。。
   Next
Next

--  作者:ssqq
--  发布时间:2009/12/21 13:58:00
--  
原来定义集合类型数据类型有这么2种语法
Dim Names As New List of(String)
Dim Names As List of(String)
--  作者:ssqq
--  发布时间:2009/12/23 21:03:00
--  
不行,还是错误,我已经使用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
图片点击可在新窗口打开查看