简体   繁体   中英

COMException error: 80040154 Class not registered in microsoft.office.interop.excel.application C#

I'm trying to make a application which will print some values to the excel file, for this I'm trying to use the Microsoft.Office.Interop.Excel library but whenever I try to create a object as mentioned below

Application xlApp = new Application();

I'm getting COM exception

System.Runtime.InteropServices.COMException: 'Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).'

I have Microsoft Office 365 installed in my machine and also PIA are available in C:\Program Files (x86)\Microsoft Visual Studio\Shared\Visual Studio Tools for Office\PIA .

Is this right way to initalize the object.

I got the same issue and found solution here .

Here is one way to proceed:

Dim xlApp As Excel.Application = New Microsoft.Office.Interop.Excel.Application()
Dim xlWorkBook = xlApp.Workbooks.Add
[...]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM