References Can't Find 'ExcelDataReader'.

Apr 9, 2012 at 10:26 PM

Forgive me is this is in another discussion, but I couldn't find it. I am using 'Excel' and 'ICSharpCode.SharpZipLib', but when the code has something like:

// the ExcelDataReader takes a System.IO.Stream object     

IExcelDataReader excelReader = new ExcelDataReader(FileUpload1.FileContent);     

FileUpload1.FileContent.Close();

DataSet wb = excelReader.WorkbookData;

// get the first worksheet of the workbook     

DataTable dt = excelReader.WorkbookData.Tables[0];
GridView1.DataSource = dt.AsDataView();     

GridView1.DataBind();

I get an error saying 'the type or namsespace name 'ExcelDataReader' could not be found.

I also can't find it searching through the Object Browser either. What am I missing?

Apr 13, 2012 at 6:43 PM

In your soution, add a new solution folder named 'Libraries'

Copy the .dlls from the download folder into the Libraries folder

In your solution, add a reference to the dlls you just added

Cheers

Apr 13, 2012 at 7:14 PM
Edited Apr 13, 2012 at 7:16 PM

Thanks so much for the response. Now, when you say 'In your solution, add a new solution' do you really mean 'solution' or is it 'project'. I didn't know you could have other solutions in a solution. i'll try it and see.

I’m only just grasping more in-depth aspects of the environment, and it seems like every time I have a small mental victory, it’s short-lived by the fact that I run into another stumbling block which takes me hours to figure out. Have a good weekend. Cheers. ~R

Apr 13, 2012 at 9:20 PM
Edited Apr 13, 2012 at 9:23 PM

I hear ya... I keep running into stumbling blocks as well, as I too am a newbie to using this project.

What I meant was, in the project, web site, whatever you are working in where you wish to use the ExcelDataReader, follow my instructions in there. FYI, adding the library folder is simply something I like to do to keep seperate any dlls that aren't created by default when my working solution is created. You could skip that step and simply add reference to the Excel dll (and ICSharpCode may be needed as well,  I'm not sure) . So when you add the references, simply browse to the folder where you downloaded the dll(s) to.

After I did all this myself, I kept getting an error when my web page was loaded... the error stated that it "could not load assembly 'Excel, ..." To resolve this I added a reference to the assembies section in the web.config file, and had to ensure the dlls were added to the GAC. That allowed to page to load. I am working in a SharePoint environment , so perhaps this will not happen to you.

Currently, I am at a new stumbling block which is described here: http://exceldatareader.codeplex.com/discussions/346801

Good luck

 

 

 

Apr 13, 2012 at 9:31 PM

I assumed that's what you meant. I have already referenced the DLLs from a folder external to the project. After your response, I tried to bring them into the Project, with no change. I even brought all of the source code in, but got some different issues. I'm not getting an assembly error, just telling that 'the type or namsespace name 'ExcelDataReader' could not be found'.

Not sure if it will help but...

using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Excel;
using ICSharpCode;

namespace PartStructChkSht
{
  public partial class adminPart : System.Web.UI.Page
  {
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void grdListUser_RowCommand(object sender, GridViewCommandEventArgs e)
    {
      int intRowFocus = Convert.ToInt32(e.CommandArgument);
      GridViewRow row = grdListUser.Rows[intRowFocus];

      Validate();
    }

    protected void btnUpload_Click(object sender, EventArgs e)
    {
      // the ExcelDataReader takes a System.IO.Stream object
      IExcelDataReader excelReader = new ExcelDataReader(uplPartFile.FileContent);
      uplPartFile.FileContent.Close();


    }

  }

}
It's the line that starts 'IExcelDataReader excelReader...' that's getting me.

I wish you well with your issue, and wish that I was further along that I may be able to help. 

Apr 13, 2012 at 9:51 PM
Edited Apr 13, 2012 at 9:55 PM
  1. After you imported the dlls into your project, you did delete the original references and added new one to point to the dlls in your project, right?  

     2.  Hmmm, I see that you have your using statements, so this suggestion is probably no good, but try prefixing   IExcelDataReader with 'Excel', like so: Excel.IExcelDataReader

     3. Otherwise, the sample code I have shows IExcelDataReader as :

         FileStream stream = File.Open(filePath, FileMode.Open, FileAccess.Read);

         IExcelDataReader excelDataReader = ExcelReaderFacftory.CreateOpenXmlReader(stream);

        That is different from what you have... see code sample at: http://exceldatareader.codeplex.com/ 

        Where did your get your code sample from?

 

 

 

 

Apr 13, 2012 at 10:01 PM

Yeah, I made sure I had no references before I shuffled the DLLs around and re-referenced them. The code came from a separate online reference, so I'll try to go through the codeplex.

I've tried the 'ExcelReaderFactory' reference also and get the same error as 'ExcelDataReader'. 

You're a peach. Thanks for all of your help.

Apr 13, 2012 at 10:08 PM
Edited Apr 13, 2012 at 10:11 PM

Alright, good luck.  I'm cutting out. Peace! When you get it figured out, post your solution.