2017-06-02 186 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();