Excel:Handle exception for workbook.open

0

How to handle exception in "C#" for the errors like->

Code:
Workbooks.Open(folderPath,filename,Excel.XlPlatform.xlWindows,"",""....)

"System.Runtime.InteropServices.COMException (0x80070BBC): Office has detected a problem with this file. To help protect your computer this file cannot be opened.
at Excel.Workbooks.Open"

Few excels work without error,but few throw above error. Please suggest some answers. Thanks.

c#
excel
asked on Stack Overflow Oct 31, 2012 by user1495475 • edited Oct 31, 2012 by K_B

1 Answer

0

Try following code to open Excel file:

    String connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + excelFilePath + ";Extended Properties=Excel 12.0;";
    // Create connection object by using the preceding connection string.
    OleDbConnection objConn = new OleDbConnection(connString);
    // Open connection with the database.
    objConn.Open();
answered on Stack Overflow Oct 31, 2012 by usman mehmood

User contributions licensed under CC BY-SA 3.0