2016-12-14 44 views
0

我讀了一些關於這個主題的其他線程,但它仍然dosn't工作,我不知道爲什麼。C#獲取excel工作表沒有辦公室unsing OLEDB

有一個例外:'Microsoft.ACE.OLEDB.12.0'-Provider未在本地機器上註冊。我已經安裝了Office 2007和2010的數據庫引擎。

您有什麼想法嗎?

OS:Win 7的教授64位

static void Main(string[] args) 
     { 
      OleDbConnection connection = null; 
      DataTable Sheets = null; 

      String file = args[0]; 
      String filePath = Path.GetDirectoryName(args[0]); 
      String connPath = ""; 

      if(Path.GetExtension(file).Equals(".xls")) 
       connPath = "Provider=Microsoft.Jet.OleDb.4.0; Data Source=" + file + ";Extended Properties=Excel 8.0"; 
      else 
       connPath = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + file + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=1\""; 

      try 
      { 
       connection = new OleDbConnection(connPath); 
       connection.Open(); 

      Sheets = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null); 

...

回答

0

發現了它。您需要編譯x86 CPU的項目。任何CPU都不行。

謝謝

+0

這不是直接回答你的問題,但正如你所看到的,使用OLEDB有很多限制。如果你想完全控制辦公室文件(沒有辦公室),你可能想看看openxml sdk:https://msdn.microsoft.com/en-us/library/office/bb448854.aspx?f=255&MSPPError=- 2147217396 –

相關問題