0

我想在 Visual Studio 2010 高级版中将一些数据写入 excel 文件,但是当我运行我的代码时,出现此错误:

comexception was unhandled by user code 
Exception from HRESULT: 0x800A03EC

我在详细视图中的错误:

System.Runtime.InteropServices.COMException was unhandled by user code
  Message=Exception from HRESULT: 0x800A03EC
  Source=Microsoft.Office.Interop.Excel
  ErrorCode=-2146827284
  StackTrace:
       at Microsoft.Office.Interop.Excel.Workbooks.Open(String Filename, Object UpdateLinks, Object ReadOnly, Object Format, Object Password, Object WriteResPassword, Object IgnoreReadOnlyRecommended, Object Origin, Object Delimiter, Object Editable, Object Notify, Object Converter, Object AddToMru, Object Local, Object CorruptLoad)
       at Cagri.Button1_Click(Object sender, EventArgs e) in c:\Users\Erdi\Documents\Visual Studio 2010\WebSites\DBE_Yazilim\Cagri.aspx.cs:line 117
       at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
       at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException: 

我使用 microsoft office 2013,我有参考资料:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
using Microsoft.Office.Interop.Excel;

最后我在以下代码部分中出现了这个错误:

workbook = excelObj.Workbooks.Open(HttpContext.Current.Server.MapPath("~/") + fileName, 0, false, Type.Missing, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", true, false, Type.Missing, true, 0, 0);

我的完整代码:

 Microsoft.Office.Interop.Excel.Application excelObj = null;
 Microsoft.Office.Interop.Excel.Workbook workbook = null;

 excelObj = new Microsoft.Office.Interop.Excel.Application();

string fileName = "DBE_BAKIM_FORMU" + ".xlsx";

System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");

        workbook = excelObj.Workbooks.Open(HttpContext.Current.Server.MapPath("~/") + fileName, 0, false, Type.Missing, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", true, false, Type.Missing, true, 0, 0);
        Microsoft.Office.Interop.Excel.Sheets sheets = workbook.Worksheets;
        Microsoft.Office.Interop.Excel.Worksheet worksheet = (Microsoft.Office.Interop.Excel.Worksheet)sheets.get_Item(1);

        worksheet.Cells[6, 3] = c.TalepTarihi.ToString();
        worksheet.Cells[7, 3] = c.TalepTuru;
        worksheet.Cells[8, 3] = c.ModulAdi;
        worksheet.Cells[9, 3] = c.EkranRaporAdi;
        worksheet.Cells[10, 3] = c.VerilenSure; 
        worksheet.Cells[11, 4] = c.USER.UserName +" " +c.USER.UserSurname;
        worksheet.Cells[12, 4] = Convert.ToInt64(c.USER.UserTel);

        workbook.Save();

        excelObj.Workbooks.Close();
        excelObj.Application.Quit();

提前谢谢..为什么我会犯这个错误?请帮忙..

4

1 回答 1

0

检查您的 Excel 插件。删除其他应用程序的插件。众所周知,福昕阅读器 PDF 插件会破坏许多不同的平台和应用程序——Visual Studio、Matlab、Labview ......。是福昕阅读器让我伤心了一个星期。

于 2017-04-17T23:01:55.183 回答