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


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

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

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


加好友 发短信
等级:四尾狐 帖子:824 积分:6288 威望:0 精华:0 注册:2012/3/1 3:17:00
专业报表问题请教老师  发帖心情 Post By:2013/2/1 18:10:00 [只看该作者]

上图上项目,如图所示金额,金额2,金额3,金额4,金额位置是固定的,想实现金额2,3,4三列中不管哪列有没有数据存在都按金额的上一行开始向上排列,除非三列内容都为空,请教老师

 

 

 

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 CurRow As Row = Tables("表A").Current
If CurRow.IsNull("金额")  Then
    CurRow("金额") = Nothing
Else
    rt.Cells(6,4).Text= "金额"
    Dim money2 As String = Tables("表A").Current("金额")
    rt.Cells(6, 11 - money2.length).Text = GetDigit(CInt(money2), money2.Length) '等于"¥"
    For i As Integer = 11 To 12 - money2.Length Step -1
        rt.Cells(6, i).Text = GetDigit(CInt(money2), 11-i)
    Next
End If

If CurRow.IsNull("金额2")  Then
    CurRow("金额2") = Nothing
Else
    rt.Cells(5,4).Text= "金额2"
    Dim money2 As String = Tables("表A").Current("金额2")
    rt.Cells(5, 11 - money2.length).Text = GetDigit(CInt(money2), money2.Length) '等于"¥"
    For i As Integer = 11 To 12 - money2.Length Step -1
        rt.Cells(5, i).Text = GetDigit(CInt(money2), 11-i)
    Next
End If

If CurRow.IsNull("金额3")  Then
    CurRow("金额3") = Nothing
Else
    rt.Cells(4,4).Text= "金额3"
    Dim money2 As String = Tables("表A").Current("金额3")
    rt.Cells(4, 11 - money2.length).Text = GetDigit(CInt(money2), money2.Length) '等于"¥"
    For i As Integer = 11 To 12 - money2.Length Step -1
        rt.Cells(4, i).Text = GetDigit(CInt(money2), 11-i)
    Next
End If

If CurRow.IsNull("金额4")  Then
    CurRow("金额4") = Nothing
Else
    rt.Cells(3,4).Text= "金额4"
    Dim money2 As String = Tables("表A").Current("金额4")
    rt.Cells(3, 11 - money2.length).Text = GetDigit(CInt(money2), money2.Length) '等于"¥"
    For i As Integer = 11 To 12 - money2.Length Step -1
        rt.Cells(3, i).Text = GetDigit(CInt(money2), 11-i)
    Next
End If

doc.Body.Children.Add(rt)
doc.AutoRotate = False '禁止自动旋转打印内容
doc.PageSetting.Landscape = True '横向打印
Doc.Preview() '预览报表

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:管理项目9.zip


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

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


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

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

 回到顶部
帅哥哟,离线,有人找我吗?
lin_hailun
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | 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() '预览报表

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


加好友 发短信
等级:四尾狐 帖子:824 积分:6288 威望:0 精华:0 注册:2012/3/1 3:17:00
  发帖心情 Post By:2013/2/1 18:35:00 [只看该作者]

按上面的代码的话金额2,3,4三列内容都在固定位置,如果某列为空的时候固定的位置也为空了,就像图这样,只有金额4有内容
图片点击可在新窗口打开查看此主题相关图片如下:图3.png
图片点击可在新窗口打开查看

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


加好友 发短信
等级:四尾狐 帖子:824 积分:6288 威望:0 精华:0 注册:2012/3/1 3:17:00
  发帖心情 Post By:2013/2/1 18:36:00 [只看该作者]

想实现除了金额列外,不管金额2,3,4中哪列为空,都按金额列位置为基础向上排列,如图所示
图片点击可在新窗口打开查看此主题相关图片如下:图2.png
图片点击可在新窗口打开查看

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


加好友 发短信
等级:四尾狐 帖子:824 积分:6288 威望:0 精华:0 注册:2012/3/1 3:17:00
  发帖心情 Post By:2013/2/1 18:38:00 [只看该作者]

就有点像这行代码一样rt.Cells(4, 11 - money2.length).Text = GetDigit(CInt(money2), money2.Length) '等于"¥",不管金额为几位数,""¥",符号都会跟在最大那位前面

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


加好友 发短信
等级:四尾狐 帖子:824 积分:6288 威望:0 精华:0 注册:2012/3/1 3:17:00
  发帖心情 Post By:2013/2/1 19:02:00 [只看该作者]

感谢林老师,这个代码执行后是按从上到下,能否按从下到上?

 回到顶部
帅哥哟,离线,有人找我吗?
lin_hailun
  8楼 | 信息 | 搜索 | 邮箱 | 主页 | 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 定义的顺序就行了。

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


加好友 发短信
等级:四尾狐 帖子:824 积分:6288 威望:0 精华:0 注册:2012/3/1 3:17:00
  发帖心情 Post By:2013/2/1 20:31:00 [只看该作者]

原来是这样,终于解决可了

 

图片点击可在新窗口打开查看

 

图片点击可在新窗口打开查看非常感谢林老师的帮助,前面想用IF语句判断,想下指定的列数太多,判断要出一堆


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


加好友 发短信
等级:四尾狐 帖子:824 积分:6288 威望:0 精华:0 注册:2012/3/1 3:17:00
  发帖心情 Post By:2013/2/1 21:24: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)      这里定义变量数值的值
        If money <> 0 Then
            rt.Cells(count+2,4).Text = colName            这里将指定行的文本等于数组

 

上面的表达不是很好,请老师见谅,如果指定行的文本自己设置的话要怎么改?比如 像rt.Cells(2,4).Text= "杂费"  不以列的名称做文本,还有比如rt.Cells(2,4).Text=Tables("表A").Current("第五列")  也就是文本值等于第五列的内容, 两个学生都需要


 回到顶部
总数 24 1 2 3 下一页