2013-01-01 109 views
2

我試圖通過C#創建一個Excel文檔。當我運行應用程序,它提供了以下錯誤:加載類型庫/ DLL時出錯(Microsoft.Office.Interop.Excel.Application)

Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Excel.Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{000208D5-0000-0000-C000-000000000046}' failed due to the following error: Error loading type library/DLL. (Exception from HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY)).

enter image description here

這是工作的罰款之前,我已經升級,從2010 的Visual Studio 2012年。我也從2010年到2013年升級辦公室

  • 在輸出窗口沒有錯誤/警告。
  • 的Microsoft.Office.Interop.Excel引用添加

回答

2

我被這個錯誤了幾天掙扎。我終於找到了解決方案。

這是因爲我已經安裝了Office 2013而不是Office 2010,我使用的是舊版本的項目。在我升級Office後,該項目不再能夠鏈接Excel參考。

即使我引用了新的Excel庫,它是15.0,它沒有工作。

我所做的是:

  • 刪除Excel引用(的Microsoft.Office.Interop.Excel)。版本 15.0,在我的情況。
  • 安裝Microsoft Excel(無論版本,你一直在使用2010年版對我來說)
  • 添加Excel引用(較老的一個。 版本14.0,在我的情況)