3

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)

mesutpiskin
  • 1,771
  • 2
  • 26
  • 30
  • What is the application, a desktop app, a service, a website? – Equalsk Sep 06 '17 at 12:48
  • Opps! sory, this is a windows service application. – mesutpiskin Sep 06 '17 at 12:50
  • 2
    5 cents here. Please note that MS [does not recommend nor support Windows Server Excel automation](https://support.microsoft.com/en-us/help/257757/considerations-for-server-side-automation-of-office). Sooner or later you might hit a wall especially when dealing with security and need of interactive user session. Looks like its still early and you might have some room to consider other options. – Janis S. Sep 06 '17 at 12:51
  • @JanisS. what do you think i should do? – mesutpiskin Sep 06 '17 at 12:55
  • 1
    @mesutpiskin there is a section in the link about alternatives. Though those will not give a good options if you are dependent on Excel engine, e.g., if you need to make formula calculations, graphs. In this case you might consider solutions where you have control of data types and use Excel as one of outputs generated using `OpenXML` with calculations done up in the data stream. – Janis S. Sep 06 '17 at 13:00
  • 1
    @jenis S. thanks for answer. – mesutpiskin Sep 06 '17 at 21:24

5 Answers5

1

Installing MS office in servers to run office. Interop assemblies in your project is the best option.

Again if you don't want to install MS office at all on server machine, Then you can install PIA (Primary Interop Assemblies)

http://msdn.microsoft.com/en-us/library/kh3965hw.aspx

Download link for PIA for office.

http://www.microsoft.com/downloads/details.aspx?FamilyID=59daebaa-bed4-4282-a28c-b864d8bfa513&DisplayLang=en

Adam
  • 2,532
  • 1
  • 24
  • 34
1

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

mesutpiskin
  • 1,771
  • 2
  • 26
  • 30
1

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).

1

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. Something about the how the C: drive was mounted was breaking the Microsoft.Office.Interop.Excel.Workbook SaveAs2 function call. I tried a lot of other common fixes found online but this was the only thing that worked.

0

Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(pathExcel, null,false);

need open readonly = false