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


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

主题:专业报表金额列问题,请教老师

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


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

以专业报表形式打印,如图所示想实现将金额个数拆分排列该如何实现,在帮助文件中看到用"GetDigit"

试了半天无效,请教老师,代码如下:

 

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 = "元"
With Tables("表A")
    For r As Integer = 0 To .Rows.Count - 1 '遍历关联表每一行
        rt.Cells(r+2,0).Text = .rows(r)("金额")
    Next
End With
doc.Body.Children.Add(rt)
doc.AutoRotate = False '禁止自动旋转打印内容
doc.PageSetting.Landscape = True '横向打印
Doc.Preview() '预览报表

 

rt.Cells(r+2,0).Text = .rows(r)("金额") 这行代码该怎么改?

 

rt.Cells(r+2,0).Text = .rows(r).GetDigit("金额",6)  这样不行

 

rt.Cells(r+2,0).Text = .rows.GetDigit(r("金额"),6)  也不行

 


此主题相关图片如下:图1.png
按此在新窗口浏览图片
 下载信息  [文件大小:   下载次数: ]
点击浏览该文件:管理项目9.zip


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


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

 改一下这段就行了。测试有效。

With Tables("表A")
    For r As Integer = 0 To .Rows.Count - 1 '遍历关联表每一行
        Dim money As String = .rows(r)("金额")
        rt.Cells(r+2,0).Text = money
        rt.Cells(r+2,5).Text = GetDigit(CInt(money), money.Length) '等于"¥"
        For i As Integer = 10 To 11 - money.Length Step -1
            rt.Cells(r+2, i).Text = GetDigit(CInt(money), 10-i)
        Next
    Next
End With


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


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

感谢林老师帮助,学生想在这行"rt.Cells(r+2,5).Text = GetDigit(CInt(money), money.Length) '等于"¥" "再加个判断,第七个单元格为空的时候"¥"符号就在第七个单元格,第八个单元格为空的时候"¥"符号就在第八个,第六个单元格为空的时候"¥"符号就在第六个,试了下下面的代码不行,该怎么改?如图所示

 

If rt.Cells(r+2,6).Text = "" Then
rt.Cells(r+2,6).Text = GetDigit(CInt(money), money.Length) '等于"¥"
ElseIf rt.Cells(r+2,5).Text = "" Then
rt.Cells(r+2,5).Text = GetDigit(CInt(money), money.Length) '等于"¥"
End If


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


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

发现上传问题,上传附件的话要先上传再打字,要不会提示"不要重复上传"上传就失败了
图片点击可在新窗口打开查看此主题相关图片如下:图1.png
图片点击可在新窗口打开查看

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


加好友 发短信
等级:狐神 帖子:6708 积分:34304 威望:0 精华:11 注册:2012/8/18 23:10:00
  发帖心情 Post By:2013/1/30 15:49: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 = "元"
With Tables("表A")
    For r As Integer = 0 To .Rows.Count - 1 '遍历关联表每一行
        Dim money As String = .rows(r)("金额")
        rt.Cells(r+2,0).Text = money
        rt.Cells(r+2, 10 - money.length).Text = GetDigit(CInt(money), money.Length) '等于"¥"
        For i As Integer = 10 To 11 - money.Length Step -1
            rt.Cells(r+2, i).Text = GetDigit(CInt(money), 10-i)
        Next
    Next
End With
doc.Body.Children.Add(rt)
doc.AutoRotate = False '禁止自动旋转打印内容
doc.PageSetting.Landscape = True '横向打印
Doc.Preview() '预览报表

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


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

图片点击可在新窗口打开查看林老师太棒了,实现了学生想要的功能

 

在论坛搜索半天,有人做出了以表的形式,有人做出了以窗口的形式,加上现在林老师做出了以报表的形式,完美了


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


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

图片点击可在新窗口打开查看遗憾的是学生看不懂代码的意思,还有只知道For ...Next是循环,而循环的条件未参透,慢慢学习了

 

rt.Cells(r+2, 10 - money.length).Text = GetDigit(CInt(money), money.Length) '等于"¥"
        For i As Integer = 10 To 11 - money.Length Step -1
            rt.Cells(r+2, i).Text = GetDigit(CInt(money), 10-i)
        Next


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


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

 没有多难,就是根据你数据的长短来设置。

 money是值,money.length是值的长度,然后分别截取值填入适当的单元格。

 回到顶部