以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]清空0值 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=158300) |
||||
-- 作者:hanlingli111999 -- 发布时间:2020/11/14 22:44:00 -- [求助]清空0值 老师好,我专业报表打印,搞 了一天,仍有2个问题未解决 1.未填写数据的单元格出现0值,想实现如未填充数据,则显示空白行 因水平有限,请老师帮该一下代码,谢谢 Syscmd.Column.UnHide() Dim doc As New PrintDoc Dim rt As New Prt.RenderTable Dim rx As prt.RenderText Dim cnt As Integer Dim tb As Table = Tables("计算表") Dim ColNames As New List(Of String) For Each cl As Col In tb.Cols \'排除隐藏列 If cl.Visible Then ColNames.Add(cl.Name) End If Next rt.Style.Font = tb.Font rt.Style.GridLines.All = New prt.LineDef(0.3,Color.LightGray) rt.CellStyle.Spacing.All = 1 rt.Style.Font = tb.Font Dim drs As List(Of DataRow) Dim pds As List(Of String) = tb.DataTable.GetValues("计算部位",tb.Filter) Dim md As New prt.RenderText md.Text = ApplicationTitle.split(".")(0) md.Style.Font = New Font("宋体", 16, FontStyle.Bold) md.Style.TextAlignHorz = prt.AlignHorzEnum.Center md.Style.Spacing.Bottom = 3 Doc.body.Children.Add(md) For c As Integer = 0 To ColNames.count - 1 \'生成列标题 rt.Cells(0,c).Text = ColNames(c) rt.Cols(c).Width = tb.Cols(ColNames(c)).PrintWidth Next For Each pd As String In pds \'分产品打印 If tb.Filter > "" Then drs = tb.DataTable.Select("计算部位 = \'" & pd & "\' And " & tb.Filter) Else drs = tb.DataTable.Select("计算部位 = \'" & pd & "\'" ) End If For Each dr As DataRow In drs \'逐行打印此产品的订单 cnt = rt.Rows.Count For c As Integer = 0 To tb.Cols.Count - 1 rt.Cells(cnt, c).Text = dr(tb.Cols(c).Name) Next Next cnt = rt.Rows.Count rt.Cells(cnt, 0).Text = "小计 " & pd \'打印产品的小计 rt.Cells(cnt,8).Text = tb.compute("Sum(重量t)", "计算部位 = \'" & pd & "\'") rt.Cells(cnt,9).Text = tb.compute("Sum(油漆面积㎡)", "计算部位 = \'" & pd & "\'") Next cnt = rt.Rows.Count rt.Cells(cnt, 0).Text = "合计 " \'打印合计 rt.Cells(cnt, 8).Text = tb.compute("Sum(重量t)") rt.Cells(cnt, 9).Text = tb.compute("Sum(油漆面积㎡)") rt.Cols.Insert(0) \'在左边插入一列,用于打印行号 rt.Cols(0).Width = 10 \'设置行号列的宽度 For i As Integer = 1 To rt.Rows.Count - 1 rt.Cells(i,0).text = i \'逐行写入行号 Next doc.Body.Children.Add(rt) doc.PageSetting.Landscape = True \'横向打印 doc.Preview()
|
||||
-- 作者:有点蓝 -- 发布时间:2020/11/15 20:24:00 -- 1、空值判断参考:http://www.foxtable.com/webhelp/topics/0595.htm 如判断是否为空再写入单元格: if dr.isnull(tb.Cols(c).Name) = false then rt.Cells(cnt, c).Text = dr(tb.Cols(c).Name) endif 2、事情都说过了所有的tb.Cols这种用法都改为使用ColNames,上面仍然存在 For c As Integer = 0 To tb.Cols.Count - 1
|
||||
-- 作者:hanlingli111999 -- 发布时间:2020/11/16 7:22:00 -- 以下是引用有点蓝在2020/11/15 20:24:00的发言:
1、空值判断参考:http://www.foxtable.com/webhelp/topics/0595.htm
如判断是否为空再写入单元格: if dr.isnull(tb.Cols(c).Name) = false then rt.Cells(cnt, c).Text = dr(tb.Cols(c).Name) endif 2、事情都说过了所有的tb.Cols这种用法都改为使用ColNames,上面仍然存在 For c As Integer = 0 To tb.Cols.Count - 1 老师,我按照您说的修改,仍出错,现上传实例,请您调试一下
|
||||
-- 作者:有点蓝 -- 发布时间:2020/11/16 8:33:00 -- 没看到实例,把改后的代码重新发上来 |
||||
-- 作者:hanlingli111999 -- 发布时间:2020/11/16 8:43:00 --
|
||||
-- 作者:hanlingli111999 -- 发布时间:2020/11/16 8:43:00 -- 修改后的代码无法保存,保存就出错 |
||||
-- 作者:有点蓝 -- 发布时间:2020/11/16 8:49:00 -- 仍然没改 For c As Integer = 0 To tb.Cols.Count - 1 改为 For c As Integer = 0 To ColNames.Count - 1 接下来的用法自行相应改改
|
||||
-- 作者:hanlingli111999 -- 发布时间:2020/11/16 8:57:00 -- 修改后出错提示,无法保存 |
||||
-- 作者:有点蓝 -- 发布时间:2020/11/16 9:03:00 -- 接下来的几行代码都要相应改改啊,应该不是使用tb.Cols了 |
||||
-- 作者:hanlingli111999 -- 发布时间:2020/11/16 9:05:00 -- 老师,好了,“”单体数量“”0值还在呀 |