{“Exception from HRESULT: 0x800A03EC”} at Microsoft.Office.Interop

吃可爱长大的小学妹 提交于 2019-12-11 02:19:50

问题


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();
}

回答1:


check this link: http://www.c-sharpcorner.com/UploadFile/jayendra/5443/

check the section where it says "Exception from HRESULT: 0x800A03EC"

hope it works.




回答2:


In the code:

  • A1 should not be zero;
  • A1 should be > 0;
  • Range rng = (Excel.Range)worksheet.get_Range((object)worksheet.Cells[1, 1], (object)worksheet.Cells[3,3])


来源:https://stackoverflow.com/questions/7008096/exception-from-hresult-0x800a03ec-at-microsoft-office-interop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!