I am trying to create an excel file using the below code in an ASP.Net web applcation.
The code works normally when I run from visual studio, but an exception occur workbook.Close command when I deploy the application on IIS and run the deployed version.
Excel.Application exc = null;
try
{
exc = new Excel.Application();
Excel.Workbooks workbooks = exc.Workbooks;
Excel._Workbook workbook = workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet);
Excel._Worksheet worksheet = (Excel._Worksheet)workbook.Worksheets[1];
Excel.Range range = worksheet.get_Range("A1", System.Reflection.Missing.Value);
Object[] data = new Object[] { "" };
range.GetType().InvokeMember("Value", System.Reflection.BindingFlags.SetProperty, null, range, data);
workbook.Close(true, p_sTempFileName, null);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + "\n" + ex.InnerException);
Console.ReadLine();
}
finally
{
if (exc != null)
exc.Quit();
}
check this link: http://www.c-sharpcorner.com/UploadFile/jayendra/5443/
check the section where it says "Exception from HRESULT: 0x800A03EC"
hope it works.
In the code:
Range rng = (Excel.Range)worksheet.get_Range((object)worksheet.Cells[1, 1], (object)worksheet.Cells[3,3])
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.