我正在尝试使用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)运行dcomcnfg打开组件服务
2)展开“组件服务”->“计算机”->“我的计算机”->“DCOM配置”
3)找到“Microsoft Excel应用程序”。
4)右键单击以打开属性对话框
5)单击“安全”选项卡,
6)“启动和激活权限,配置权限,添加权限 - 在管理员用户(此用户),交互式用户和启动用户下运行”
7)启动和激活权限+访问权限+配置权限=>添加IIS_IUSRS + Network Service具有完全控制权**
2. 将将转换.xls文件的项目的构建从“任何 CPU”更改为“x86”,并在本地机器上发布此库至服务器。
有人解决了这个问题吗? 我已经努力解决这个问题两天了。