C# Excel 2010 工作簿打开错误

标签 c# excel-2010

我们最近从 Excel 2007 升级到 Excel 2010,我们发现现有代码开始失败。

异常信息:

Office has detected a problem with this file. To help protect your computer this file cannot be opened.

我们已经追踪到打开文件的行

excelApp.Workbooks.Open

即使手动打开文件,也会出现 protected View 消息框。

我们如何使用 C# 解决这个问题。

最佳答案

看看使用 Application.FileValidation Property (Excel)在您的 Open 语句之前。

Returns or sets how Excel will validate files before opening them. Read/write

Files that do not pass validation will be opened in a Protected View window. If you set the FileValidation property, that setting will remain in effect for the entire session the application is open.

您可以将其设置为 MsoFileValidationMode Enumeration 中的枚举值之一

msoFileValidationDefault

msoFileValidationSkip

如果在 Open 语句之前将其设置为 msoFileValidationSkip,它应该会绕过检查。

有点像

excelApp.FileValidation = MsoFileValidationMode.msoFileValidationSkip;

在公开声明之前。

关于C# Excel 2010 工作簿打开错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11970265/

相关文章:

c# - 如何捕获本地主机上生成的 SOAP 请求?

c# - 合并两个数据库表的 LINQ 代码?

c# - 如何检查是否已安装 IIS 6 Management Compatibility 功能?

excel - 如何在 VBA 中创建数据透视表

c# - 等待异步 TaskEx

c# - 通过 StateClient 访问本地主机机器人的用户数据,该机器人在没有事件的情况下未注册

excel - 更改宏的默认图标

java.lang.ArrayIndexOutOfBoundsException 从 Excel 文件读取

VBA:插入具有动态范围和相对引用的公式

excel - 计算excel行中的连续条纹