• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 14612
  • Last Modified:

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;
            }

      }

0
gmoconno
Asked:
gmoconno
1 Solution
 
e1vCommented:
try
 using Excel = Microsoft.Office.Interop.Excel;
0
 
gmoconnoAuthor Commented:
Thanks alot e1v. No more errors. A bit new to this thing.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now