Link to home
Start Free TrialLog in
Avatar of gmoconno
gmoconno

asked on

The type or namespace name 'Excel' could not be found (are you missing a using directive or an assembly reference?)

Hi,

I am using Microsoft Visual Studio.NET 2003. I am trying to do somw work with EXCEL and keep getting the following error.

The type or namespace name 'Excel' could not be found (are you missing a using directive or an assembly reference?)

I have added the following to the project:

Microsoft Excel 11.0 Object Library
Microsoft Office 11.0 Object Library
Microsoft XP PIA's


the following is my code but it doesn't seem to recognise        using Excel;
Wwould appreciate any help.

using System;
using Excel;
using System.Collections;


namespace exer
{
      class ExcelClass
      {
            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            private string Cfilename;
            public    Excel.Application excelApp ; // Creates a new Excel Application
            public Excel.Workbook excelWorkbook;
            public Excel.Sheets excelSheets;
            public Excel.Worksheet excelWorksheet;

            public void Start(string filename)
            {
                  Cfilename=filename;
                  excelApp = new Excel.ApplicationClass();
                  excelWorkbook = excelApp.Workbooks.Open(filename, 0,
                        false, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true,
                        false,  0, true, false, false);
            }          
            public void openSheet(string currentSheet)           // The following gets the Worksheets collection
            {
                                   
                  excelSheets = excelWorkbook.Worksheets;
                                   
                  excelWorksheet = (Excel.Worksheet)excelSheets.get_Item(currentSheet);
            }
            public void setcell(string val)
            {
                                   
                  // The following gets cell A1 for editing
                  excelSheets = excelWorkbook.Worksheets;
                  Excel.Range excelCell = (Excel.Range)excelWorksheet.get_Range("A1", "A1");

                  // The following sets cell A1's value to "Hi There"
                  excelCell.Value2 = val;
            }
            public void view()
            {
                  excelApp.Visible=true;// Makes Excel visible to the user.
            }
            public void Close()
            {
                  excelWorkbook.Close(false,Cfilename,false);
                  excelApp.Quit();
                  excelApp=null;
            }

      }

ASKER CERTIFIED SOLUTION
Avatar of e1v
e1v

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gmoconno
gmoconno

ASKER

Thanks alot e1v. No more errors. A bit new to this thing.