简体   繁体   中英

Error while saving the workbook : System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x800A03EC

I am creating an excel file with my asp.net application. I am hosting this site on IIS7 .

When i run it from server, it is giving error while saving the workbook.

my code

Workbook.SaveAs(Server.MapPath("Folder") + "\\" + filename + ".xls"
, Excel.XlFileFormat.xlHtml, objOpt, objOpt, false, false
,Excel.XlSaveAsAccessMode.xlShared, false, false, objOpt, objOpt);

I have been trying to solve this for a week. hope I ll find some help here

This is my error

System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x800A03EC 

I am using Office 2000,IIS7 . I have set all the authorizations. Any suggestions are highly appreciated.

Interop is not supported in sever-scenarios (like IIS) by MS .

There are many options to read/edit/create Excel files without Interop/installing Excel on the server:

MS provides the free OpenXML SDK V 2.0 - see http://msdn.microsoft.com/en-us/library/bb448854%28office.14%29.aspx (XLSX only)

This can read+write MS Office files (including Excel).

Another free option see http://www.codeproject.com/KB/office/OpenXML.aspx (XLSX only)

IF you need more like handling older Excel versions (like XLS, not only XLSX), rendering, creating PDFs, formulas etc. then there are different free and commercial libraries like ClosedXML (free, XLSX only), EPPlus (free, XLSX only), Aspose.Cells , SpreadsheetGear , LibXL and Flexcel etc.

Have you set 'Read-Only' property to 'true' when opening the workbook ?

Refer following on how to open a workbook with write access :

Microsoft.Office.Interop.Excel.Application xlApp = null;
Microsoft.Office.Interop.Excel.Workbook xlWorkBook = null;

xlApp = new Excel.ApplicationClass();
xlWorkBook = xlApp.Workbooks.Open(txtFilePath.Text, 0, false, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);

A value 'false' for 3rd parameter of 'xlApp.Workbooks.Open' method denotes that the workbook will not be read-only.

This is just a wild guess, since you have not shared any code about how you open a workbook. Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM