Excel“外部表的格式不正確”
“外部表的格式不正確。” 嘗試使用帶有以下連接字符串的Excel2007文件時,通常會發(fā)生這種情況:Microsoft.Jet.OLEDB.4.0和Extended Properties = Excel 8.0
使用以下連接字符串似乎可以解決大多數(shù)問題。
public static string path = @'C:srcRedirectApplicationRedirectApplication301s.xlsx';public static string connStr = 'Provider=Microsoft.ACE.OLEDB.12.0;Data Source=' + path + ';Extended Properties=Excel 12.0;';解決方法
我正在嘗試使用下面顯示的代碼讀取Excel(xlsx)文件。我得到一個“外部表不是預(yù)期的格式。”錯誤,除非我已經(jīng)在Excel中打開了文件。換句話說,我必須先在Excel中打開文件,然后才能從C#程序中讀取文件。xlsx文件在我們的網(wǎng)絡(luò)上共享。如何讀取文件而不必先打開它?謝謝
string sql = 'SELECT * FROM [Sheet1$]';string excelConnection = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' + pathname + ';Extended Properties='Excel 8.0;HDR=YES;IMEX=1;'';using (OleDbDataAdapter adaptor = new OleDbDataAdapter(sql,excelConnection)) { DataSet ds = new DataSet(); adaptor.Fill(ds);}
相關(guān)文章: