C# Excel 2010 Workbook Open error

前端 未结 3 678
無奈伤痛
無奈伤痛 2021-01-01 03:26

We recently upgraded from Excel 2007 to Excel 2010, and we have found that existing code started failing.

Exception Message:

Office has detect

3条回答
  •  耶瑟儿~
    2021-01-01 03:55

    Have a look at using Application.FileValidation Property (Excel) before your Open statement.

    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.

    You can set it to one of the enum values in MsoFileValidationMode Enumeration

    msoFileValidationDefault

    msoFileValidationSkip

    if you set it to msoFileValidationSkip before the Open statement, it should bypass the check.

    Something like

    excelApp.FileValidation = MsoFileValidationMode.msoFileValidationSkip;
    

    before the open statement.

提交回复
热议问题