Microsoft.Office.Interop.Excel._Workbook.SaveAs()异常:0x800A03EC

Microsoft.Office.Interop.Excel._Workbook.SaveAs() Exception: 0x800A03EC(Microsoft.Office.Interop.Excel._Workbook.SaveAs()异常:0x800A03EC)
本文介绍了Microsoft.Office.Interop.Excel._Workbook.SaveAs()异常:0x800A03EC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在服务器上运行时遇到了保存EXCEL电子表格的问题,当在本地运行时,它工作得很好!

以前有没有人遇到过这个问题,或者能给我指出正确的方向?

应用程序池正在‘LocalSystem’标识下运行。

谢谢!

我一直收到以下错误/堆栈跟踪:

Error saving the excel sheet: 
Exception from HRESULT: 0x800A03EC   at     Microsoft.Office.Interop.Excel._Workbook.SaveAs(Object Filename, Object FileFormat, 
Object     Password, Object WriteResPassword, Object ReadOnlyRecommended, Object 
CreateBackup,     XlSaveAsAccessMode AccessMode, Object ConflictResolution, Object 
AddToMru, Object     TextCodepage, Object TextVisualLayout, Object Local)
   at MiFiveDayReport.ExportToExcel.SaveAs(String filepath, XlFileFormat type) in
G:DevelopmentMI DevelopmentTechnical     DevelopmentMIPortalMIPortalOld_App_CodeExportToExcel.cs:line 411

以下是我尝试保存Excel文档时使用的代码:

try
        {
            if (log.IsInfoEnabled) log.Info("Saving...");
            if (string.IsNullOrEmpty(filepath))
                //Sets the filepath as the default
                excelBook.SaveAs(this.filepath, type);
            else
                excelBook.SaveAs(filepath, type);
            if (log.IsInfoEnabled) log.Info("Saved!");
            success = true;
        }
        catch (Exception ex)
        {
            //SendEmail e = new SendEmail("Error saving excel sheet: " + ex.Message);
            //SendEmail e1 = new SendEmail("Error saving excel sheet: " + ex.StackTrace);
            if (log.IsErrorEnabled) log.Error("Error saving the excel sheet: "
                                     + ex.Message
                                     + ex.StackTrace);
            throw;
        }

已更新新错误:

Error creating excel application: 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.RuntimeTypeHandle.CreateInstance(RuntimeType type, 
Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at MiFiveDayReport.ExportToExcel..ctor(String filepath) in G:DevelopmentMI DevelopmentTechnical DevelopmentMIPortalMIPortalOld_App_CodeExportToExcel.cs:line 94

在以下行:

try
        {
            if (log.IsInfoEnabled) log.Info("Creating an excel application...");
            excelApp = new Application();
            if (log.IsInfoEnabled) log.Info("Excel application created");
        }
        catch (Exception ex)
        {
            if (log.IsErrorEnabled) log.Error("Error creating excel application: " + ex.Message + ex.StackTrace);
            throw;
        }

推荐答案

1)开始->运行->MMC-32->按Enter键 将打开新窗口 2)文件->添加删除管理单元->从可用管理单元中选择组件服务 ->按添加>按钮 3)展开组件服务->展开计算机->展开MyComputer->展开DCOM配置->右键单击Microsoft Excel应用程序->属性-> 安全选项卡 4)在启动和激活权限部分->点击Customize单选按钮,然后点击编辑按钮 5)点击Add(添加)按钮->Add Your User(添加用户),为您的用户提供所有访问权限 然后按OK按钮(您的服务帐户正在执行您的应用程序)

之后 请创建以下提及文件夹

如果我们运行的是Windows Server 2008 64位/R2, ·导航到C:WindowsSysWOW64configsystem配置文件文件夹,并创建以下目录"Desktop" 如果我们在32位Windows Server中运行 ·导航到C:WindowsSystem32configsystemprofileDesktop文件夹并创建以下目录"Desktop"

这将解决此问题。

这篇关于Microsoft.Office.Interop.Excel._Workbook.SaveAs()异常:0x800A03EC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)