`
king_tt
  • 浏览: 2123399 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

VB.NET 开发中遇到的兼容性检查问题

 
阅读更多

事情是这样的:

我们的一个应用程序需要通过VSTO代码方式操作本地的Excel,包括打开工作簿,生成新的工作簿,设置数据,并且保存为新文件等等。

该程序在Excel 2003的环境下没有任何问题,但是在Excel 2007或者是Excel 2010中就老是遇到中途被卡住的状况。

究其原因,是因为我们想将文件继续保存为Excel 2003格式,但Excel 2007或者Excel 2010默认会有一个兼容性检查的功能。如下

image

如果将“Check compatiblity when saving this workbook”的选项关闭,则问题可以解决。

但是,如果你无法确保用户那边关闭了该选项,也可以通过程序的方式临时关闭检查

有两种方式实现这样的需求

第一种:在Application级别关闭警告

        If (app Is Nothing) Then
            app = New Excel.Application
            app.Interactive = False
            app.UserControl = False
            app.DisplayAlerts = False
            app.Visible = False
            app.ScreenUpdating = False
        End If
<style type="text/css"> <!-- .csharpcode, .csharpcode pre {font-size:small; color:black; font-family:consolas,"Courier New",courier,monospace; background-color:rgb(255,255,255)} .csharpcode pre {margin:0em} .csharpcode .rem {color:rgb(0,128,0)} .csharpcode .kwrd {color:rgb(0,0,255)} .csharpcode .str {color:rgb(0,96,128)} .csharpcode .op {color:rgb(0,0,192)} .csharpcode .preproc {color:rgb(204,102,51)} .csharpcode .asp {background-color:rgb(255,255,0)} .csharpcode .html {color:rgb(128,0,0)} .csharpcode .attr {color:rgb(255,0,0)} .csharpcode .alt {background-color:rgb(244,244,244); width:100%; margin:0em} .csharpcode .lnum {color:rgb(96,96,96)} --> </style>

第二种:在Workbook级别关闭警告

wb.CheckCompatibility=False


还有一个情况就是,如果你关闭了警告(不管是手工地,还是代码关闭),却又想恢复该选项。要按照下面这样做

image
在上面的对话框中,点击“Check Compatibility”,你将可以继续勾选上这个选项。
image

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics