Error for ExcelDataReader

14,783

Solution 1

Go to Project -> Manage NuGet Packages..., in opened window select Browse tab and type Excel Data Reader, install it, at the top of your class add using Excel. Then you will be able to use interface IExcelDataReader.

Here is the source:

https://forums.asp.net/t/1981566.aspx?The+type+or+namespace+name+IExcelDataReader+could+not+be+found

Solution 2

In older versions of ExcelDataReader - like 2.1.2.3 - it uses an Excel namespace for itself, I mean that namespace is not related to Microsoft Office Excel, that I can suggest you to use alias for them:

using XlReader = Excel;
using Xl = Microsoft.Office.Interop.Excel;

...

var excelReader = XlReader.ExcelReaderFactory.CreateOpenXmlReader(stream);

But in newer version - like 3.1.0 - its namespace changed to ExcelDataReader;
You can install the package of ExcelDataReader 2.1.2.3 that will remove your compile exception.

Solution 3

Go to your project-> right click on References and click on Manage NuGet Packages a new tab would opened in your IDE if you are using VS 2015 or higher otherwise a pop window would open. enter package name and install.

Share:
14,783

Related videos on Youtube

Rituja Nashikkar
Author by

Rituja Nashikkar

Updated on June 04, 2022

Comments

  • Rituja Nashikkar
    Rituja Nashikkar almost 2 years

    I am doing a project in C# and I have downloaded ExcelDataReader from codeplex and added it to my project reference. There is an error in namespace 'using Excel;' though I have added Excel, Excel.4.5, Microsoft.Office.Interop.Excel to my project references. I'm getting error where I have written

     IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
    

    The errors are quoted below:

    The type or namespace name 'ExcelDataReader' could not be found (are you missing a using directive or an assembly reference?) The name 'ExcelReaderFactory does not exist in the current context

    How to deal with these errors?
    Thank you in advance.

    PS:- I have added 'using Excel = Microsoft.Office.Interop.Excel' directive as well.

    • Souvik Ghosh
      Souvik Ghosh over 6 years
      Try changing 'using Excel = Microsoft.Office.Interop.Excel' to 'using Microsoft.Office.Interop.Excel'
    • JBO
      JBO over 6 years
      Try to install the excel reference via nugget. Nugget will do the job for you and then you should be able to resolve the dependency.
    • Rituja Nashikkar
      Rituja Nashikkar over 6 years
      @SouvikGhosh i made changes as per ur suggestion and now I'm getting a new error "'DataTable' is an ambiguous reference between 'System.Data.DataTable' and 'Microsoft.Office.Interop.Excel.DataTable'."
    • Rituja Nashikkar
      Rituja Nashikkar over 6 years
      @JBO I am new to .NET and C#...I don't know what nuggets are and how to use them
    • JBO
      JBO over 6 years
      @RitujaNashikkar Ok, in your visual studio, you go to Tools > "Nuget Package Manager" > "Manage Nuget Packages For Solution". It will open a window where you will be able to look for the reference you need.
    • Rituja Nashikkar
      Rituja Nashikkar over 6 years
      @JBO There is no such option in Tools...What to do now?
    • JBO
      JBO over 6 years
      Look the answer posted by @Michal Turcyzn, it says the thing as me but more detailed.
  • Rituja Nashikkar
    Rituja Nashikkar over 6 years
    Sir, there is no option as 'Manage NuGet Packages' in Project tab. Not under any other tab in visual studio. Seems like I'm missing it in my machine.