HI

I want to read Excel file from C#,below I menation the coding I use,
I add Microsoft Excel 12.0 object library ,but Once I complie the coding it gave me error Meassage.The Error Meassage is
1."Type of Namespace for Application class Doesnt exsits"
2.Excel.Application.Workbook(object) is a method,which not given valid in the given context.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Excel;
namespace ExcelTest2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            Excel.Application  xl = new Excel.ApplicationClass();

            Excel.Workbook wb = xl.Workbooks.Open("D:\\Test\\Test.xls", 0, false, 5, System.Reflection.Missing.Value, System.Reflection.Missing.Value, false, System.Reflection.Missing.Value, System.Reflection.Missing.Value, true, false, System.Reflection.Missing.Value, false, false, false);

        }
    }
}

Recommended Answers

All 4 Replies

Add using Microsoft.Office.Interop.Excel;

HI

I add that reference also but still error meassage is exists
."The type or namespace name 'ApplicationClass' does not exist in the namespace 'Excel' "

Thanks
Tank50

Application not ApplicationClass!
== Microsoft.Office.Interop.Excel.Application xl = new Microsoft.Office.Interop.Excel.Application();

HI
Great it works now,Thanks Ramy Mahrous.

Tank50

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.