Foxtable(狐表)用户栏目专家坐堂 → [求助]在Excel报表中加入清零代码(搞定)


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

主题:[求助]在Excel报表中加入清零代码(搞定)

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


加好友 发短信
等级:三尾狐 帖子:787 积分:6349 威望:0 精华:0 注册:2008/9/1 8:26:00
[求助]在Excel报表中加入清零代码(搞定)  发帖心情 Post By:2010/7/27 10:43:00 [只看该作者]

在命令窗口可以执行

With Tables("分组统计")
    .Select(0 ,0, .Rows.Count - 1, .Cols.Count - 1)
End With
Dim Book As New XLS.Book(ProjectPath & "Attachments\权属统计表.xls") '打开模板
Book.Build() '生成细节区
Book.Save("D:\My Documents\退耕报表\权属统计表.xls") '保存工作簿
Dim App As New MSExcel.Application
Dim Wb As MSExcel.Workbook = App.WorkBooks.Open("D:\My Documents\退耕报表\权属统计表.xls")
Dim Wd As MSExcel.Window = Wb.Windows(1)    '表示当前工作簿窗口
Wd.DisplayZeros = False                 '不显示0值
App.Visible = True


 

单个报表好处理,下面是批量生成的代码该如何加入清零设置?

Dim Names() As String
If DataTables.Contains("分组统计") '如果存在分组统计
    If Forms("操作选项").Controls("ComboBox1").Value >"" Andalso Forms("操作选项").Controls("ComboBox2").Value >"" Andalso Forms("操作选项").Controls("CheckBox3").Checked=True Then
        Names = New String() {"结果分析","林种统计","面积统计","秋季验收","补助测算","坡度统计","权属统计","设计汇总","设计统计","投资测报","预算汇总","植被统计","验收汇总","二期补助"}
    Else
        Names = New String() {"结果分析表","林种统计表","面积统计表","秋季验收表","补助测算表","坡度统计表","权属统计表","设计汇总表","设计统计表","投资测报表","预算汇总表","植被统计表","验收汇总表","二期补助表"}
    End If
    For Each Name As String In Names
        With Tables("分组统计")
            .Select(0 ,0, .Rows.Count - 1, .Cols.Count - 1)
        End With
        Dim Book As New XLS.Book(ProjectPath & "Attachments\" & Name & ".xls") '打开模板
        Book.Build() '生成细节区
        Book.Save("D:\My Documents\退耕报表\"& Name & ".xls") '保存工作簿
        Dim Proc As New Process '打开工作簿
        Proc.File ="D:\My Documents\退耕报表\"& Name & ".xls"
        Proc.Start()
    Next
Else
    MessageBox.Show("先统计!", "提示")
End If

[此贴子已经被作者于2010-7-28 17:15:23编辑过]

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


加好友 发短信
等级:三尾狐 帖子:787 积分:6349 威望:0 精华:0 注册:2008/9/1 8:26:00
  发帖心情 Post By:2010/7/28 17:02:00 [只看该作者]

看了《FoxTable操控Excel全攻略》自己摸索就搞定了,清除Excel报表单元格中的“0”值看起来清晰多了。

Dim Names() As String
If DataTables.Contains("分组统计") '如果存在分组统计
    If Forms("操作选项").Controls("ComboBox1").Value >"" Andalso Forms("操作选项").Controls("ComboBox2").Value >"" Then
        Names =  New String() {"结果分析","林种统计","面积统计","秋季验收","补助测算","坡度统计","权属统计","设计汇总","设计统计","投资测报","预算汇总","植被统计","验收汇总","二期补助"}
    Else
        Names = New String() {"结果分析表","林种统计表","面积统计表","秋季验收表","补助测算表","坡度统计表","权属统计表","设计汇总表","设计统计表","投资测报表","预算汇总表","植被统计表","验收汇总表","二期补助表"}
    End If
    For Each Name As String In Names
        With Tables("分组统计")
            .Select(0 ,0, .Rows.Count - 1, .Cols.Count - 1)
        End With
        Dim Book As New XLS.Book(ProjectPath & "Attachments\" & Name & ".xls") '打开模板
        Book.Build() '生成细节区
        Book.Save("D:\My Documents\退耕报表\"& Name & ".xls") '保存工作簿
        Dim App As New MSExcel.Application
        Dim Wb As MSExcel.Workbook = App.WorkBooks.Open("D:\My Documents\退耕报表\"& Name & ".xls")
        Dim Wd As MSExcel.Window = Wb.Windows(1)    '表示当前工作簿窗口
        Wd.DisplayZeros = False                 '不显示0值
        App.Visible = True
        Wb.Save
    Next
Else
    MessageBox.Show("先统计!", "提示")
End If


 回到顶部