diana onea

diana onea

  • NA
  • 8
  • 16.9k

c# import Excel Files - error references

Jun 6 2011 1:41 PM
Hello 

I have a small problem. I want to import Excel files using C# but when i declare a variable like this xlsApp = new Excel.ApplicationClass() I receive this error : The type or namespace name 'ApplicationClass' does not exist in the namespace 'Excel' (are you missing an assembly reference?

I added the following references : Microsoft Excel 12.0 Object Library, Microsoft Excel 5.0 Object Library and Microsoft.Office.Interlop.Excel and it stil dosen`t work. 

This is my code

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

namespace PC_Management3
{
    public partial class BrowseExcel : Form
    {
        public BrowseExcel()
        {
            InitializeComponent();
        }

       
        private void button1_Click(object sender, EventArgs e)
        {
            //open file

            OpenFileDialog fdlg = new OpenFileDialog();
            fdlg.InitialDirectory = @"d:\";
            fdlg.Filter = "All files (*.xls)|*.xls|All files (*.*)|*.*";
            fdlg.FilterIndex = 2;
            fdlg.RestoreDirectory = true;
            if (fdlg.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = fdlg.FileName;
            }

            //excel stuff
            Excel.Application xlsApp;
            Excel.Workbook xlsWorkbook;
            Excel.Worksheets xlsWorksheet;

            xlsApp = new Excel.ApplicationClass();


        }

        
    }
}

Answers (5)