以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 专业报表问题请教老师 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=28535) |
||||
-- 作者:mamuaiqing -- 发布时间:2013/2/1 18:10:00 -- 专业报表问题请教老师 上图上项目,如图所示金额,金额2,金额3,金额4,金额位置是固定的,想实现金额2,3,4三列中不管哪列有没有数据存在都按金额的上一行开始向上排列,除非三列内容都为空,请教老师
Dim doc As New PrintDoc \'定义一个报表 Doc.PageSetting.TopMargin = 2 \'设置上边距 rt = New prt.RenderTable \'创建表格对象 If CurRow.IsNull("金额2") Then If CurRow.IsNull("金额3") Then If CurRow.IsNull("金额4") Then doc.Body.Children.Add(rt)
![]() ![]() |
||||
-- 作者:lin_hailun -- 发布时间:2013/2/1 18:16:00 -- 未明白……,向上排列什么意思,要的效果呢? |
||||
-- 作者:lin_hailun -- 发布时间: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 -- 发布时间:2013/2/1 18:35:00 -- 按上面的代码的话金额2,3,4三列内容都在固定位置,如果某列为空的时候固定的位置也为空了,就像图这样,只有金额4有内容 ![]() ![]() |
||||
-- 作者:mamuaiqing -- 发布时间:2013/2/1 18:36:00 -- 想实现除了金额列外,不管金额2,3,4中哪列为空,都按金额列位置为基础向上排列,如图所示 ![]() ![]() |
||||
-- 作者:mamuaiqing -- 发布时间:2013/2/1 18:38:00 -- 就有点像这行代码一样rt.Cells(4, 11 - money2.length).Text = GetDigit(CInt(money2), money2.Length) \'等于"¥",不管金额为几位数,""¥",符号都会跟在最大那位前面 |
||||
-- 作者:mamuaiqing -- 发布时间:2013/2/1 19:02:00 -- 感谢林老师,这个代码执行后是按从上到下,能否按从下到上? |
||||
-- 作者:lin_hailun -- 发布时间:2013/2/1 19:46:00 -- 以下是引用mamuaiqing在2013-2-1 19:02:00的发言: 感谢林老师,这个代码执行后是按从上到下,能否按从下到上? 呃,楼主,修改一下 colNames 定义的顺序就行了。 |
||||
-- 作者:mamuaiqing -- 发布时间:2013/2/1 20:31:00 -- 原来是这样,终于解决可了
|
||||
-- 作者:mamuaiqing -- 发布时间:2013/2/1 21:24:00 -- Dim colNames() As String = {"金额", "金额2", "金额3", "金额4"} 这里定义变量了数组 With Tables("表A")
上面的表达不是很好,请老师见谅,如果指定行的文本自己设置的话要怎么改?比如 像rt.Cells(2,4).Text= "杂费" 不以列的名称做文本,还有比如rt.Cells(2,4).Text=Tables("表A").Current("第五列") 也就是文本值等于第五列的内容, 两个学生都需要 |