Foxtable(狐表)用户栏目专家坐堂 → 专业报表问题请教老师


  共有11706人关注过本帖树形打印复制链接

主题:专业报表问题请教老师

帅哥哟,离线,有人找我吗?
lin_hailun
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:狐神 帖子:6708 积分:34304 威望:0 精华:11 注册:2012/8/18 23:10:00
  发帖心情 Post By:2013/2/1 18:16:00 [显示全部帖子]

 未明白……,向上排列什么意思,要的效果呢?

 回到顶部
帅哥哟,离线,有人找我吗?
lin_hailun
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:狐神 帖子:6708 积分:34304 威望:0 精华:11 注册:2012/8/18 23:10:00
  发帖心情 Post By:2013/2/1 18:34:00 [显示全部帖子]

 这样………………

Dim doc As New PrintDoc '定义一个报表
Dim rt As New prt.RenderTable() '定义一个表格对象
Dim rx As New prt.RenderText '定义一个文本对象

Doc.PageSetting.TopMargin = 2 '设置上边距
Doc.PageSetting.BottomMargin = 0 '设置下边距
Doc.PageSetting.RightMargin = 1 '设置右边距
Doc.PageSetting.LeftMargin = 0 '设置左边距

rt = New prt.RenderTable '创建表格对象
rt.x = 0
rt.y = 32
rt.Style.Font = New Font("宋体", 11 ) '设置字体
rt.Rows(0).Style.Font = New Font("宋体", 10 ) '惟独第一行字体大小为10
rt.Rows(1).Style.Font = New Font("宋体", 10 ) '惟独第一行字体大小为10
rt.Style.GridLines.All = New prt.Linedef '设置网格线
rt.Style.Padding.Left = 0 '左边距5毫米
rt.Rows.Count = 10 '设置总行数
rt.Cols.Count = 14 '设置总列数
rt.Height = 88 '设置表格的高度为80毫米
rt.Width = 198 '设置表格的宽度为198
rt.Rows(0).Height = 6 '设置第1行的高度为6毫米,剩余高度被平均分排到其他行
rt.Rows(1).Height = 6 '设置第2行的高度为6毫米,剩余高度被平均分排到其他行
rt.Rows(9).Height = 12 '设置第2行的高度为6毫米,剩余高度被平均分排到其他行
rt.Cols(0).Width = 30
rt.Cols(1).Width = 20
rt.Cols(2).Width = 20
rt.Cols(3).Width = 10
rt.Cols(4).Width = 20
rt.Cols(5).Width = 4
rt.Cols(6).Width = 4
rt.Cols(7).Width = 4
rt.Cols(8).Width = 4
rt.Cols(9).Width = 4
rt.Cols(10).Width = 4
rt.Cols(11).Width = 12
rt.Cols(12).Width = 20
rt.Cells(0,0).SpanRows = 2 '第1行第1个单元格向下合并2行
rt.Cells(0,1).SpanRows = 2 '第1行第2个单元格向下合并2行
rt.Cells(0,2).SpanRows = 2 '第1行第3个单元格向下合并2行
rt.Cells(0,3).SpanRows = 2 '第1行第4个单元格向下合并2行
rt.Cells(0,4).SpanRows = 2 '第1行第5个单元格向下合并2行
rt.Cells(0,11).SpanRows = 2 '第1行第12个单元格向下合并2行
rt.Cells(0,12).SpanRows = 2 '第1行第13个单元格向下合并2行
rt.Cells(0,13).SpanRows = 2 '第1行第13个单元格向下合并2行
rt.Cells(2,13).SpanRows = 3 '第3行第13个单元格向下合并2行
rt.Cells(5,13).SpanRows = 4 '第6行第13个单元格向下合并2行
rt.Cells(0,5).SpanCols = 6 '第1行第6个单元格向右合并6列
rt.Cells(9,1).SpanCols = 12 '第7行第1个单元格向右合并5列
rt.Style.TextAlignVert = prt.AlignVertEnum.Center '内容垂直居中
rt.Style.TextAlignHorz = prt.AlignHorzEnum.Center '水平居中排列
rt.Style.FontBold = True '字体加粗
rt.Cells(0,5).Text = "金    额"
rt.Cells(1,6).Text = "万"
rt.Cells(1,7).Text = "千"
rt.Cells(1,8).Text = "百"
rt.Cells(1,9).Text = "十"
rt.Cells(1,10).Text = "元"

Dim colNames() As String = {"金额", "金额2", "金额3", "金额4"}

Dim count As Integer = 0
For Each colname As String In colNames
    With Tables("表A")
        Dim money As String = .Current(colname)
        If money <> 0 Then
            rt.Cells(count+2,4).Text = colName
            rt.Cells(count+2, 10 - money.length).Text = GetDigit(CInt(money), money.Length) '等于"¥"
            For i As Integer = 10 To 11 - money.Length Step -1
                rt.Cells(count+2, i).Text = GetDigit(CInt(money), 10-i)
            Next
            count += 1
        End If
    End With
Next
doc.Body.Children.Add(rt)
doc.AutoRotate = False '禁止自动旋转打印内容
doc.PageSetting.Landscape = True '横向打印
Doc.Preview() '预览报表

 回到顶部
帅哥哟,离线,有人找我吗?
lin_hailun
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:狐神 帖子:6708 积分:34304 威望:0 精华:11 注册:2012/8/18 23:10:00
  发帖心情 Post By:2013/2/1 19:46:00 [显示全部帖子]

以下是引用mamuaiqing在2013-2-1 19:02:00的发言:
感谢林老师,这个代码执行后是按从上到下,能否按从下到上?


呃,楼主,修改一下 colNames 定义的顺序就行了。

 回到顶部
帅哥哟,离线,有人找我吗?
lin_hailun
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:狐神 帖子:6708 积分:34304 威望:0 精华:11 注册:2012/8/18 23:10:00
  发帖心情 Post By:2013/2/2 9:31:00 [显示全部帖子]

 那就这样写。

Dim colNames() As String = {"金额|第五列", "金额2|第六列", "金额3|第七列", "金额4|第八列"}    这里定义变量了数组
Dim count As Integer = 0
For Each colname As String In colNames                这里循环变量遍历数组 

With Tables("表A")
        Dim money As String = .Current(colname.split("|")(0))      这里定义变量数值的值
        If money <> 0 Then
            rt.Cells(count+2,4).Text = colname.split("|")(1)            这里将指定行的文本等于数组



 回到顶部
帅哥哟,离线,有人找我吗?
lin_hailun
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:狐神 帖子:6708 积分:34304 威望:0 精华:11 注册:2012/8/18 23:10:00
  发帖心情 Post By:2013/2/3 15:54:00 [显示全部帖子]

 随便改成什么都可以的,遇到什么问题?

 回到顶部
帅哥哟,离线,有人找我吗?
lin_hailun
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:狐神 帖子:6708 积分:34304 威望:0 精华:11 注册:2012/8/18 23:10:00
  发帖心情 Post By:2013/2/4 10:48:00 [显示全部帖子]

以下是引用mamuaiqing在2013-2-3 16:59:00的发言:
金额|第五列,显示出来的文本"第五列",如果文本内容来自第五列内容呢?


Dim colNames() As String = {"金额|第五列|bind", "金额2|第六列", "金额3|第七列", "金额4|第八列"}    这里定义变量了数组
Dim count As Integer = 0
For Each colname As String In colNames                这里循环变量遍历数组 

With Tables("表A")
        Dim money As String = .Current(colname.split("|")(0))  
        If money <> 0 Then
            rt.Cells(count+2,4).Text = iif(colname.split("|").Length=3, .Current(colname.split("|")(1)), colname.split("|")(1))



 回到顶部
帅哥哟,离线,有人找我吗?
lin_hailun
  7楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:狐神 帖子:6708 积分:34304 威望:0 精华:11 注册:2012/8/18 23:10:00
  发帖心情 Post By:2013/2/5 8:36:00 [显示全部帖子]

以下是引用mamuaiqing在2013-2-5 1:08:00的发言:

执行上面的代码后实现了可以根据指定列内容进行显示,但发现个问题"金额2|第六列"   显示的是列名,如果将"金额2|第六列"改为 "金额2|杂费"  提示杂费不属于表A

 


呃,你这样该,好吧?

"金额2|第六列", "金额3|杂费|bind"

 回到顶部
帅哥哟,离线,有人找我吗?
lin_hailun
  8楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:狐神 帖子:6708 积分:34304 威望:0 精华:11 注册:2012/8/18 23:10:00
  发帖心情 Post By:2013/2/5 12:28:00 [显示全部帖子]

 确实,iif是所有的都运算一遍的,用if判断吧。

Dim colNames() As String = {"金额|第五列|bind", "金额2|第列", "金额3|第七列", "金额4|第八列"}
Dim count As Integer = 0
For Each colname As String In colNames
   
    With Tables("表A")
        Dim money As String = .Current(colname.split("|")(0))
        If money <> 0 Then
            If colname.split("|").Length=3 Then
                rt.Cells(count+2,4).Text =  .Current(colname.split("|")(1))
            Else
                rt.Cells(count+2,4).Text = colname.split("|")(1)
            End If
            rt.Cells(count+2, 10 - money.length).Text = GetDigit(CInt(money), money.Length) '等于"¥"
            For i As Integer = 10 To 11 - money.Length Step -1
                rt.Cells(count+2, i).Text = GetDigit(CInt(money), 10-i)
            Next
            count += 1
        End If
    End With
Next

 回到顶部