简体   繁体   English

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

[英]Microsoft.Office.Interop.Excel._Workbook.SaveAs() Exception: 0x800A03EC

I'm having issues with saving an excel spreadsheet when running on the server, when running locally, it works beautifully!在服务器上运行时,我在保存 excel 电子表格时遇到问题,在本地运行时,它工作得很好!

Has anyone ever come across this before or can point me in the right direction?有没有人以前遇到过这个或者可以指出我正确的方向?

The app pool is running under the 'LocalSystem' identity.应用程序池在“LocalSystem”身份下运行。

Thanks!谢谢!

I keep getting the following error/ stack trace:我不断收到以下错误/堆栈跟踪:

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

Here is the code I use to try and save the excel doc:这是我用来尝试保存 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;
        }

Updated New Error:更新了新错误:

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

On the following line:在以下行中:

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) start -> run -> mmc -32 -> press enter new window will open 2) file-> add remove snap in-> from avilable snap ins select component services -> press add> button 3) expand component services-> expand computers -> expand mycomputer -> expand DCOM config -> right click on Microsoft Excel application -> properties -> security tab 4) in launch and activation permission section -> click on customize radio button and then click on edit button 5) click add button -> add your user and provide all the access to your user and press ok button (service account with you are executing your app) 1)开始->运行-> mmc -32->按Enter将打开新窗口2)文件->添加删除管理单元->从可用管理单元中选择组件服务->按添加>按钮3)展开组件服务->展开计算机->展开mycomputer->展开DCOM配置->右键单击Microsoft Excel应用程序->属性->安全选项卡4)在启动和激活权限部分中->单击自定义单选按钮,然后单击编辑按钮5)单击添加按钮->添加您的用户并提供对该用户的所有访问权限,然后按确定按钮(您正在使用的服务帐户正在执行您的应用)

after this please create the below mention folder 在此之后,请创建以下提到的文件夹

If we are running in Windows Server 2008 64-bit/R2, · Navigate to C:\\Windows\\SysWOW64\\config\\systemprofile folder and create the following directory “Desktop” If we are running in Windows Server 32-bit · Navigate to C:\\Windows\\System32\\config\\systemprofile\\Desktop folder and create the following directory “Desktop” 如果我们在64位/ R2的Windows Server 2008中运行,·导航到C:\\ Windows \\ SysWOW64 \\ config \\ systemprofile文件夹并创建以下目录“ Desktop”如果我们在32位的Windows Server中运行·导航至C :\\ Windows \\ System32 \\ config \\ systemprofile \\ Desktop文件夹并创建以下目录“ Desktop”

This will solve this issue. 这样可以解决这个问题。

I have gone to hell and back with Microsoft.Office.Interop.Excel.Workbook and I found that the fix to not use the C:\ drive on my AWS windows system but the D:\ drive.我已经死了又回来了 Microsoft.Office.Interop.Excel.Workbook,我发现修复不使用 C:\ 驱动器在我的 AWS windows 系统上,而是 D:\ 驱动器。 Something about the how the C: drive was mounted was breaking the Microsoft.Office.Interop.Excel.Workbook SaveAs2 function call.关于 C: 驱动器的安装方式的一些事情打破了 Microsoft.Office.Interop.Excel.Workbook SaveAs2 function 调用。 I tried a lot of other common fixes found online but this was the only thing that worked in my case.我尝试了很多在网上找到的其他常见修复方法,但这是唯一对我有用的方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C# System.Runtime.InteropServices.COMException (0x800A03EC):HRESULT 异常:0x800A03EC Microsoft.Office.Interop.Excel._Workbook.SaveAs() - C# System.Runtime.InteropServices.COMException (0x800A03EC): Exception from HRESULT: 0x800A03EC Microsoft.Office.Interop.Excel._Workbook.SaveAs() 0x800a03ec 使用 Microsoft.Office.Interop.Excel.Workbook.Open() 时出现异常 - 0x800a03ec Exception when using Microsoft.Office.Interop.Excel.Workbook.Open() Excel Interop Exception(已安装2007,使用Office.Interop.Excel-版本1.6(12))-0x800A03EC HResult - Excel Interop Exception (2007 installed, Office.Interop.Excel used - ver 1.6 (12)) - 0x800A03EC HResult Excel Interop写入失败(HRESULT:0x800A03EC) - Excel Interop failed to write (HRESULT: 0x800A03EC) Excel 12互操作HRESULT 0x800A03EC - Excel 12 Interop HRESULT 0x800A03EC C#Excel Interop行限制-> HRESULT:0x800A03EC引发异常 - C# Excel Interop row limit -> HRESULT: 0x800A03EC exception thrown Excel Interop Worksheet副本引发异常HRESULT:0x800A03EC - Excel Interop Worksheet copy raises exception HRESULT: 0x800A03EC Excel COM 互操作 - 来自 HRESULT 的 get_Range 异常:0x800A03EC - Excel COM Interop - get_Range Exception from HRESULT: 0x800A03EC 关闭 Excel 工作簿 - System.Runtime.InteropServices.COMException:来自 HRESULT 的异常:0x800A03EC - Closing Excel Workbook - System.Runtime.InteropServices.COMException : Exception from HRESULT: 0x800A03EC HRESULT的Excel异常:0x800A03EC - Excel Exception from HRESULT: 0x800A03EC
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM