0

i want to write some datas into an excel file in visual studio 2010 premium but when i run my code, i take this error:

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

my error in detail view:

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: 

i use microsoft office 2013 and i have references:

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;

and finally i take this error in the following code part:

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

my full code:

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

thanks in advance..why i take this error? please help..

rockenpeace
  • 1,011
  • 5
  • 18
  • 29
  • 1
    Are you sure you have the correct (new) Office interop versions? There is a similar question here: http://stackoverflow.com/questions/4408336/system-runtime-interopservices-comexception-0x800a03ec – Lennart Dec 30 '12 at 11:54
  • while i was writing this code, i was using microsoft office 2007..then i have started to use microsoft office 2013..maybe reason of this error is related to this.. – rockenpeace Dec 30 '12 at 12:03
  • 1
    Well, it could be that you can't access an Excel 2013 sheet programatically with the Office 2007 PIA. For whatever reason. Here are instructions how to install the 2013 PIA, but remember to change the references in your project as well: http://olappivottableextend.codeplex.com/wikipage?title=Office%202013%20Primary%20Interop%20Assemblies – Lennart Dec 30 '12 at 12:06

1 Answers1

0

Check your Excel addins. Remove other application's addins. The Foxit Reader PDF addin is known to corrupt a lot of different platforms and applications — Visual Studio, Matlab, Labview …. It was Foxit Reader which caused me a week of grief.

Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38