我试图使用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);
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
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, …Run Code Online (Sandbox Code Playgroud) 我得到这个堆栈跟踪:
System.Runtime.InteropServices.COMException (0x800A13E9): Word ðú÷ì ááòéä.
at Microsoft.Office.Interop.Word.Documents.Add(Object& Template, Object& NewTemplate, Object& DocumentType, Object& Visible)
at Crm.DocumentGeneration.Printing.DocumentsPrinter.MergeDocuments(ApplicationClass& wordApp, IEnumerable`1 printDataItems, String tempDirectory, String template) in C:\Work\Danel.Nursing\Crm.DocumentGeneration.Printing\DocumentsPrinter.cs:line 249
Run Code Online (Sandbox Code Playgroud)
谷歌搜索后似乎COMException(0x800A13E9)是内存不足异常,但服务器上有足够的内存来启动太空船 8192太空飞船.
这是函数调用:
Document document = wordApp.Documents.Add(ref defaultTemplate, ref missing, ref missing, ref missing);
Run Code Online (Sandbox Code Playgroud)
我检查过defaultTemplate没有null或无效.
我当时正在研究这个问题。System.UnauthorizedAccessException:检索Word Interop的COM类工厂失败,错误80070005。
为了使Word Interop可以在其上工作,我们在测试服务器中安装了word。这导致了这个新错误,并且我无法应用在Componenet Services DCOM Config上找不到Microsoft Word所建议的修复程序。那么我该如何解决呢?
我有一个现有的delphi桌面应用程序,我正在重写为asp.net mvc应用程序.
桌面应用程序有大约120个excel报告.这些报告通常包含很少的命名单元格,其中包含设置信息(客户端ID等),一些数据查询返回到sql server数据和几个关键表.
要在桌面应用程序上生成报告,我使用ole自动化
我想在我的网络应用程序中这样做.但是,在服务器上不支持ole自动化,并且不起作用.我见过的所有excel组件似乎都不支持刷新查询和/或关键表.
目前,我最好的选择似乎是使用某些报表生成器重写报表并将这些报表导出到Excel.但是,生成的文件需要更长的时间来编写,功能更少(没有关键表),当然还有120个.
有关如何使用现有报告的任何建议?
更新
Excel安装在服务器上,与开发机器上的版本相同.
我的mvc代码是这样的:
objApp = new Application();
objBooks = objApp.Workbooks;
objBook = objBooks.Open(FileName);
objApp.DisplayAlerts = false; // don't warn if pivot table changed
objApp.ActiveWorkbook.RefreshAll();
objBook.SaveAs(newFileName);
Run Code Online (Sandbox Code Playgroud)
在开发机器上它工作正常,但在服务器上它在第一行失败
objApp = new Application();
Run Code Online (Sandbox Code Playgroud)
与System.UnauthorizedAccessException的:检索COM类工厂CLSID组件{00024500-0000-0000-C000-000000000046}失败,原因是以下错误:80070005次访问被拒绝.(来自HRESULT的异常:0x80070005(E_ACCESSDENIED)).