简体   繁体   English

在C#中为Excel Automation创建COM对象时出现COMException

[英]COMException when creating COM object for Excel Automation in C#

I've got this error when I create a COM object in order to use Excel automation. 创建COM对象以使用Excel自动化时出现此错误。 Any one knows why I am getting this error? 谁知道我为什么收到此错误?

System.Runtime.InteropServices.COMException(errorCode = -2146959355) Message: Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80080005. System.Runtime.InteropServices.COMException(errorCode = -2146959355)消息:由于以下错误,检索具有CLSID {00024500-0000-0000-C000-000000000046}的组件的COM类工厂失败,原因是:80080005。

The call stack is following: 调用堆栈如下:

System.Runtime.Remoting.RemotingServices.AllocateUninitializedObject(RuntimeType objectType) at System.Runtime.Remoting.RemotingServices.AllocateUninitializedObject(Type objectType) at System.Runtime.Remoting.Activation.ActivationServices.CreateInstance(Type serverType) at System.Runtime.Remoting.Activation.ActivationServices.IsCurrentContextOK(Type serverType, Object[] props, Boolean bNewObj) at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck) at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache) at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache) at System.Activator.CreateInstance(Type type, Boolean nonPublic) at Geotab.ComObject..ctor(Type type) System.Runtime.Remoting.RemotingServices.AllocateUninitializedObject(Type objectType)在System.Runtime.Remoting.Activation.Activation.ActivationServices.CreateInstance(Type serverType)在System.Runtime.Remoting。 System.RuntimeTypeHandle.CreateInstance处的Activation.ActivationServices.IsCurrentContextOK(类型serverType,Object []道具,布尔bNewObj)(System.RuntimeTypeHandle.CreateInstance(RuntimeType type,布尔publicOnly,布尔noCheck,布尔&canBeCached,RuntimeMethodHandle&ctor,布尔&bNeedSecurityCheck)在System.RuntimeType.CreateInstanceSlow(在System.RuntimeType.CreateInstanceImpl(布尔publicOnly,布尔skipVisibilityChecks,布尔fillCache)在System.Activator.CreateInstance(类型类型,布尔非公共)在Geotab.ComObject..ctor(类型类型)

This is my code: Type excelAppType = Type.GetTypeFromProgID("Excel.Application"); 这是我的代码:Type excelAppType = Type.GetTypeFromProgID(“ Excel.Application”); comExcelObject = new ComObject(excelAppType); comExcelObject =新的ComObject(excelAppType);

You need a reference to the Excel library. 您需要对Excel库的引用。 Add Reference on your project and go to the COM tab, then Microsoft Excel with the version you have. 在项目上添加引用,然后转到“ COM”选项卡,然后选择具有您所使用版本的Microsoft Excel。

The error code (0x80080005) is CO_E_SERVER_EXEC_FAILURE, "Server execution failed". 错误代码(0x80080005)为CO_E_SERVER_EXEC_FAILURE,“服务器执行失败”。 In other words, something went wrong when COM tried to start Excel.exe. 换句话说,COM尝试启动Excel.exe时出现了问题。 Pretty basic problem that has way too many possible causes. 有很多可能原因的相当基本的问题。 Check the Windows event log for a possible better diagnostic. 检查Windows事件日志以获得更好的诊断。 The usual next step is reinstalling Office. 通常的下一步是重新安装Office。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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