COM Exception 80040154 When creating an Excel Appl

2020-03-24 02:59发布

I'm trying to run my application on a server which does not and will not have Office installed on it.

using EXCEL = Microsoft.Office.Interop.Excel;
...
EXCEL.Application app = new EXCEL.Application();//Exception thrown here

The code is working fine on my own system, but on the server it gives the following exception:

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

both systems are 32bits, and I've copied the excel Interop dll next to application's exe. I've also installed O2010PIA.

any lead?

2条回答
聊天终结者
2楼-- · 2020-03-24 03:37

The Office Interop assemblies are runtime-callable wrappers (RCW) that allow you to interoperate with a copy of Office that's installed on the system via the COM API that it exposes.

The error message indicates that Excel isn't installed, exactly what I'd expect. You can't use the Interop assemblies on a machine without Office.

查看更多
Melony?
3楼-- · 2020-03-24 03:44

I'm trying to run my application on a server which does not and will not have Office installed on it.

As Joe said, you'll need to install Excel for Interop to work. If you're dead-set against that, consider third-party alternatives. In general, Microsoft does not recommend installing Office on your server and using it with Interop - that being said, it will work (at least most of the time).

查看更多
登录 后发表回答