Microsoft.Office.Interop 中的 {“HRESULT 异常:0x800A03EC”}
我正在尝试在 ASP.Net Web 应用程序中使用以下代码创建 Excel 文件。
当我从 Visual Studio 运行时,代码工作正常,但当我在 IIS 上部署应用程序并运行部署的版本时,workbook.Close 命令出现异常。
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();
}
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();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
检查此链接:http://www.c-sharpcorner.com/UploadFile/jayendra/ 章
5443
第
check this link: http://www.c-sharpcorner.com/UploadFile/jayendra/5443/
check the section where it says "Exception from HRESULT: 0x800A03EC"
hope it works.
代码中:
范围 rng = (Excel.Range)worksheet.get_Range((object)worksheet.Cells[1, 1], (object)worksheet.Cells[3,3])
In the code:
Range rng = (Excel.Range)worksheet.get_Range((object)worksheet.Cells[1, 1], (object)worksheet.Cells[3,3])