-- 作者:yyzlxc
-- 发布时间:2011/11/27 16:55:00
-- [求助]专业报表的数字格式化(已解决)
一专业报表,要求银行余额为两位小数,如何修改按钮代码,请各位老师指教,谢谢!!
按钮代码如下:
Dim doc As New PrintDoc \'定义一个新报表 Dim tb As Table = Tables("余额明细") \'捆绑表 Dim ColNames As New List(Of String) Dim prs As Integer = 30 \'每页30行 Dim sum2 As Double = 0 \'定义双精度变量(小计) Dim tsum2 As Double = 0 \'定义双精度变量(总计) For p As Integer = 0 To math.Ceiling(tb.Rows.Count / prs) - 1 \'大循环,计算共几页 Dim rt As New prt.RenderTable \'定义一个新表格 For Each cl As Col In tb.Cols \'排除隐藏列 If cl.Visible Then ColNames.Add(cl.Name) End If Next rt.Width = "Parent.Width" \'表格宽度等于容器宽度 rt.CanSplitHorz = True \'表格宽度超出页宽时,可以水平换页 rt.Style.Font = tb.Font rt.Style.Gridlines.All = New prt.Linedef(Color.Gray) \'灰色网格线 rt.CellStyle.Spacing.All = 1.0 \'单元格内距设为1.0毫米 For c As Integer = 0 To tb.Cols.Count - 1 \'逐列设置和填入内容 rt.Cells(0,c).Text = tb.Cols(c).Name \'列名作为标题 rt.Cells(0,c).Style.TextAlignHorz = prt.AlignHorzEnum.Center \'标题内容水平居中 rt.Cols(c).Width = tb.Cols(ColNames(c)).PrintWidth \'列宽等于实际列宽 If tb.Cols(ColNames(c)).IsNumeric OrElse tb.Cols(ColNames(c)).IsDate Then \'如果是数值或日期列 rt.Cols(c).Style.TextAlignHorz = prt.AlignHorzEnum.Right \'数据水平靠右 End If For r As Integer = p * prs To math.min(tb.Rows.Count - 1,( p + 1) * prs - 1) \'小循环 rt.Cells(r - p * prs + 1, c).Text = tb.rows(r)(c) Next Next sum2 = 0 For r As Integer = p * prs To math.min(tb.Rows.Count - 1,( p + 1) * prs - 1) \'累计小计 sum2 =sum2 + tb.rows(r)("银行余额") Next tsum2 = tsum2 + sum2 rt.Rows.Count = rt.Rows.Count + 1 \'增加小计行 rt.Rows(rt.Rows.count -1)(0).text = "本页小计" rt.Rows(rt.Rows.count -1)(2).text = sum2 If p < math.Ceiling(tb.Rows.Count / prs) - 1 rt.BreakAfter = prt.BreakEnum.Page Else rt.Rows.Count = rt.Rows.Count + 1 \'增加总计行 rt.Rows(rt.Rows.count -1)(0).text = "总计" rt.Rows(rt.Rows.count -1)(2).text = tsum2 End If doc.Body.Children.Add(rt) \'将表格加入到报表 Next \'设置页眉 Dim rx As New prt.RenderTable rx.Cells(0,0).Text = Date.Today rx.Cells(0,1).Text = "银行对账单" rx.Cells(0,2).Text = "第[PageNo]页,共[PageCount]页" rx.Cols(0).Style.TextAlignHorz = prt.AlignHorzEnum.Left \'水平靠左 rx.Cols(0).Style.TextAlignVert = prt.AlignVertEnum.Bottom \'垂直靠下 rx.Cols(1).Style.TextAlignHorz = prt.AlignHorzEnum.Center \'水平居中 rx.Cols(2).Style.TextAlignHorz = prt.AlignHorzEnum.right \'水平靠右 rx.Cols(2).Style.TextAlignVert = prt.AlignVertEnum.Bottom \'垂直靠下 rx.Style.Borders.Bottom = New prt.LineDef \'设置底边框 rx.CellStyle.Spacing.Bottom = 1 \'底端内容缩进1.0毫米 rx.Cells(0,1).Style.FontSize = 14 \'设置第二列行字号 rx.Cells(0,1).Style.FontBold = True \'字体加粗 Doc.PageHeader = rx \'作为页眉使用 Doc.Preview() \'预览
[此贴子已经被作者于2011-11-28 8:22:41编辑过]
|
-- 作者:yyzlxc
-- 发布时间:2011/11/27 20:30:00
--
谢谢程老师的回复,这次的问题与上次有点区别,但是参照上次的解决方案,已解决了金额列的数字格式化问题.
但是还存在小计、总计值的格式化没有解决,还望指教,谢谢!!
解决金额列格式化的代码如下:
For r As Integer = p * prs To math.min(tb.Rows.Count - 1,( p + 1) * prs - 1) \'小循环 rt.Cells(r - p * prs + 1, c).Text = tb.Rows(r)(c) If (ColNames(c)) = "银行余额" \'设置格式 rt.Cells(r - p * prs + 1, c).Text = format(tb.Rows(r)(ColNames(c)),"00.00") Else rt.Cells(r - p * prs + 1, c).Text = tb.Rows(r)(c) End If Next
|