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

时间:2013-06-14 10:42:08

标签: c# asp.net export-to-excel

我在服务器上运行时遇到保存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:\Development\MI Development\Technical     Development\MIPortal\MIPortal\Old_App_Code\ExportToExcel.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:\Development\MI Development\Technical Development\MIPortal\MIPortal\Old_App_Code\ExportToExcel.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 个答案:

答案 0 :(得分:0)

1)开始 - >跑 - > mmc -32 - >按回车键  新窗口将打开 2)file->添加删除snap in->从avilable snap ins中选择组件服务     - >按添加>按键 3)扩展组件服务 - >扩展计算机 - >扩展mycomputer - >展开DCOM配置 - >右键单击Microsoft Excel应用程序 - >属性 - > 安全选项卡 4)在启动和激活许可部分 - >单击自定义单选按钮,然后单击编辑按钮 5)点击添加按钮 - >添加您的用户并提供对您的用户的所有访问权限   然后按确定按钮(服务帐户正在执行您的应用程序)

之后 请创建以下提到的文件夹

如果我们在Windows Server 2008 64位/ R2中运行, ·导航到C:\ Windows \ SysWOW64 \ config \ systemprofile文件夹并创建以下目录“Desktop” 如果我们在Windows Server 32位运行 ·导航到C:\ Windows \ System32 \ config \ systemprofile \ Desktop文件夹并创建以下目录“Desktop”

这将解决这个问题。