c# - 服务器执行失败(HRESULT : 0x80080005 (CO_E_SERVER_EXEC_FAILURE)) 异常

标签 c# excel interop xls excel-interop

我尝试使用 Microsoft.Office.Interop.Excel.Workbook 类在服务器端将 .xls 文件转换为 .xlsx 文件,如下所示:

 workBook.SaveAs("FILENAME_HERE", XlFileFormat.xlOpenXMLWorkbook, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlNoChange, Microsoft.Office.Interop.Excel.XlSaveConflictResolution.xlLocalSessionChanges, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

我收到以下错误:

Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)). : System.Runtime.InteropServices.COMException (0x80080005): Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
   at System.Runtime.Remoting.RemotingServices.AllocateUninitializedObject(RuntimeType objectType)
   at System.Runtime.Remoting.Activation.ActivationServices.CreateInstance(RuntimeType serverType)
   at System.Runtime.Remoting.Activation.ActivationServices.IsCurrentContextOK(RuntimeType serverType, Object[] props, Boolean bNewObj)
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at System.Activator.CreateInstance(Type type)
   at CALLING_METHOD_IN_MY_LIBRARY_HERE...

问题是此错误仅发生在登台服务器上;在我的本地机器上它工作正常。

我在登台服务器上尝试过的事情:

  1. **1) 运行 dcomcnfg 打开组件服务

2) 展开“组件服务”->“计算机”->“我的电脑”->“DCOM 配置”

3) 找到“Microsoft Excel 应用程序”。

4)右键打开属性对话框

5) 单击“安全”选项卡,

6) “启动和激活权限,配置权限,已添加权限 - 在管理员用户(此用户)、交互式用户和启动用户下运行的身份

7)。启动和激活权限+访问权限+配置权限=>添加IIS_IUSRS+完全控制的网络服务**

2. 更改了在我的本地计算机上将 .xls 文件从“任何 CPU”转换为“x86”的项目的构建,并将此库发布到服务器上。

有人知道如何解决这个问题吗?我已经努力解决这个问题 2 天了。

最佳答案

使用 DCOMCNFG.exe。打开它并转到: 组件服务 -> 计算机 -> 我的电脑 -> DCOM 配置 -> Microsoft Excel 应用程序

打开属性,选择“身份”选项卡,然后选择交互式用户。

关于c# - 服务器执行失败(HRESULT : 0x80080005 (CO_E_SERVER_EXEC_FAILURE)) 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22062284/

相关文章:

c# - 获取 'excelcnv.exe' 位置

c# - 如何为 WPF ListView 禁用 XAML 中的某些项目

c# - 将变量传递到用户控件

python - 有没有办法从 python 启动 excel?

vba - 尝试在Err.Clear中使用On Error GoTo <label>

c# - P/invoke 函数采用指向结构的指针

C# + COM,修改参数中的数组

c# - 使用继承向内置类添加函数

c# - 来自 NuGet 的 System.Data.SQLite,interop dll 未复制到输出目录

python - 在python中将多个Excel文件(xlsx)附加在一起