Click here to Skip to main content
15,744,149 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
any one solve this error
Exception from HRESULT: 0x800A03EC

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsFormsApplication1
    public partial class Form1 : Form
        public Form1()

        private void btnexport_Click(object sender, EventArgs e)
            // creating Excel Application

            Microsoft.Office.Interop.Excel._Application app = new Microsoft.Office.Interop.Excel.Application();

            // creating new WorkBook within Excel application

            Microsoft.Office.Interop.Excel._Workbook workbook = app.Workbooks.Add(Type.Missing);

            // creating new Excelsheet in workbook

            Microsoft.Office.Interop.Excel._Worksheet worksheet = null;

            // see the excel sheet behind the program

            app.Visible = true;

            // get the reference of first sheet. By default its name is Sheet1.

            // store its reference to worksheet

            worksheet = workbook.Sheets["Sheet1"];

            worksheet = workbook.ActiveSheet;
            // changing the name of active sheet

            worksheet.Name = "Exported from gridview";

            // storing header part in Excel

            for (int i = 1; i < dataGridView1.Columns.Count + 1; i++)

                worksheet.Cells[1, i] = dataGridView1.Columns[i - 1].HeaderText;


            // storing Each row and column value to excel sheet

            for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)

                for (int j = 0; j < dataGridView1.Columns.Count; j++)

                    worksheet.Cells[i + 2, j + 1] = dataGridView1.Rows[i].Cells[j].Value.ToString();



            // save the application

            workbook.SaveAs("c:\\output.xls", Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                Type.Missing, Type.Missing, Type.Missing, Type.Missing);

            // Exit from the application

Updated 27-Jan-12 0:21am
Anuja Pawar Indore 27-Jan-12 6:21am    
Added pre tag
priyanka999 27-Jan-12 6:23am    

1 solution

You need to ensure that the interop files are registered on the machine.
You can reinstall the interop package. Check this out[^].
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900