2017-06-02 182 views
3

使用Microsoft.Office.Interop.Excel.dll導致以下錯誤:的Microsoft.Office.Interop.Excel未註冊DLL

An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll

Additional information: Retrieving the COM class factory for component with CLSID {00020819-0000-0000-C000-000000000046} failed due to the following error: 80040154 Klasse nicht registriert (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

錯誤在此代碼的第四行occures:

using EX = Microsoft.Office.Interop.Excel; 

private void LoopBANFDokumenteLibrary(System.Uri Link) 
{ 
     EX.Application MSExcel = new EX.Application(); 
     EX.Workbook WB = MSExcel.Workbooks.Add(new EX.Workbook()); //ERROR: Exception thrown 
     EX.Worksheet WS = WB.Worksheets.Add(new EX.Worksheet()); 
     /*...and further code...*/ 
} 

若干年前,我每天都使用這個Interop.Excel.DLL,並且從來沒有遇到過這個問題。打開REGEDIT.EXE,該dll被註冊,你可以在這個截圖中看到:

regedit

有誰有一個想法,什麼是錯?

的問候,並感謝您, 揚

+0

該錯誤generall表示不安裝Excel .. – stuartd

+0

我目前正在運行它:-) – Jan021981

+0

..它可能是一個版本不匹配? – stuartd

回答

1

變化

EX.Workbook WB = MSExcel.Workbooks.Add(new EX.Workbook()); 

EX.Workbook WB = MSExcel.Workbooks.Add(); 

同樣使用

EX.Worksheet WS = WB.Worksheets.Add();