Opening and working with excel files using C#

May 3 2011 1:34 PM
Hi Friends,
    
            I am trying to create an application that would compare two excel sheets. But to start, when i try opening an excel sheet. I am not able to do it. I am getting the following error. Can anyone help me.

I am getting the following Runtime error."Exception from HRESULT: 0x800A03EC" in the line with yellow background
Excel.XlPlatform.xlWindows


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using Excel=Microsoft.Office.Interop.Excel;
using System.Windows.Forms;
namespace WindowsApplication7
{
 public partial class Form1 : Form
 {
  public Form1()
   {
     InitializeComponent();
   }
     private void Browse_Click(object sender, EventArgs e)
      {
         Excel.Application excelApp = new Excel.ApplicationClass();
         OpenFileDialog openFileDialog1 = new OpenFileDialog();
         openFileDialog1.Filter = "Excel Files|*.xlsx";
         openFileDialog1.Title = "Select the excel file";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string filename = openFileDialog1.FileName;
                // MessageBox.Show(filename);
                string workbookPath = filename;
               
Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(workbookPath, 0, false, 5, Excel.XlPlatform.xlWindows, "", false, "", "", true, false, 0, true, false, false);
                //MessageBox.Show("Success");
                openFileDialog1.OpenFile();
            }
        }
    }
}

Answers (2)