2012-10-31 58 views
0

如何處理異常的「C#」的錯誤,喜歡 - >Excel中:處理例外workbook.open

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" 

很少有過人之處沒有錯誤的工作,但上面的錯誤少扔。 請建議一些答案。 謝謝。

回答

0

嘗試下面的代碼打開Excel文件:

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(); 
+0

感謝answer.I不'噸這樣認爲,這將我們work.How可以改變數據源嗎? – user1495475

+0

是的,很難更改數據源。但它是我建議的解決方案之一。 –