Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# System.Runtime.InteropServices.COMException (0x800A03EC): Exception from HRESULT: 0x800A03EC Microsoft.Office.Interop.Excel._Workbook.SaveAs()

Tags:

c#

windows

excel

I'm having issues with saving an excel spreadsheet when running on the Windows server 2008 and 2012 but this project its working on local pc (Windows 7,8 or 10)

C# source code

Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook excelWorkBook = excelApp.Workbooks.Add();
Microsoft.Office.Interop.Excel.Worksheet excelWorkSheet = excelWorkBook.Worksheets.Add();
excelWorkSheet.Name = "blablabla";
//added cells data
excelWorkBook.SaveAs(excelPath.ToString());
excelWorkBook.Close();
excelApp.Quit();

error message

Exception from HRESULT: 0x800A03EC System.Runtime.InteropServices.COMException (0x800A03EC): 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)

like image 464
mesutpiskin Avatar asked Dec 04 '25 13:12

mesutpiskin


2 Answers

This error is due to the fact that the local pc and the server have different office versions.I used the office 2012 references (microsoft office interop excel 14) but the server has a different version (microsoft office interop excel 12)

Step 1) I installed the same office versions. (v.12)

Step 2) Select "The interactive user" option in "Microsoft Excell Application Properties" window. https://msdn.microsoft.com/en-us/library/windows/desktop/ms686587(v=vs.85).aspx enter image description here

like image 68
mesutpiskin Avatar answered Dec 06 '25 03:12

mesutpiskin


This issue isn't caused by your code. My computer had both Office 2016 and 2010 on it, and after uninstalling 2010 and rebooting, the issue was fixed. Make sure to change the Application Reference to MS Office 14.0 Object Library (for Office 2010).

like image 39
Adelheid Kiriland Avatar answered Dec 06 '25 02:12

Adelheid Kiriland



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!