c# 调用excle 错误 HRESULT: 0x800A03EC 如何解决
源码信息:
protected void Button1_Click(object sender, EventArgs e)
{
Microsoft.Office.Interop.Excel.ApplicationClass myExcel = new Microsoft.Office.Interop.Excel.ApplicationClass();
if (myExcel == null)
{
Response.Write("无法创建Excel对象,可能您的电脑未安装Excel!");
}
Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
//新建工作簿
Microsoft.Office.Interop.Excel.Workbook workBook = excelApp.Workbooks.Add(true);
//新建工作表
Microsoft.Office.Interop.Excel.Worksheet ws = workBook.ActiveSheet as Microsoft.Office.Interop.Excel.Worksheet;
Object missing = System.Reflection.Missing.Value;
//try
//{
ws.SaveAs("c:\\temp.xls", missing, missing, missing, missing, missing, missing, missing, missing, missing);
//}
//catch(Exception ex)
//{
//System.Globalization.CultureInfo ci = System.Globalization.CultureInfo.CurrentCulture;
//Response.Write(ex.Message+"********"+ci.Name.ToString());
//}
ws.get_Range(ws.Cells[1, 1], ws.Cells[1, 3]).Value2 = "sssss";
//ws.Quit();
}
错误信息:
Exception from HRESULT: 0x800A03EC
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x800A03EC
源错误:
行 41: //try
行 42: //{
行 43: ws.SaveAs("c:\\temp.xls", missing, missing, missing, missing, missing, missing, missing, missing, missing);
行 44: //}
行 45: //catch(Exception ex)
[COMException (0x800a03ec): Exception from HRESULT: 0x800A03EC]
Microsoft.Office.Interop.Excel._Worksheet.SaveAs(String Filename, Object FileFormat, Object Password, Object WriteResPassword, Object ReadOnlyRecommended, Object CreateBackup, Object AddToMru, Object TextCodepage, Object TextVisualLayout, Object Local) +0
NewExcle.Button1_Click(Object sender, EventArgs e) in d:\Downloads\WebSite1\NewExcle.aspx.cs:43
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +115
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +140
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +29
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2981