我们最近从 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/