Click here to Skip to main content
15,909,827 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to read data from excel file using EPPlus. But i am not sure how to proceed. Please help.

public ActionResult Index()
      {
          //OpenFileDialog fileDialog = new OpenFileDialog();
          var path=Server.MapPath("~/App_Data/CompanyList.xls");
          FileStream stream = new FileStream(path, FileMode.Open);
          //FileStream str = System.IO.File.Open(fileDialog.FileName, FileMode.Open, FileAccess.Read);
          readExcel2003(stream);
          return View();
      }

      public DataSet readExcel2003(FileStream stream)
      {
          DataSet dataSet;
          //1. Reading from a binary Excel file ('97-2003 format; *.xls)
          IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
          dataSet = excelReader.AsDataSet();
          excelReader.Close();
          return dataSet;
      }



i am getting error that ExcelReaderFactory.cs is not found.
Posted
Updated 1-Apr-15 0:38am
v2
Comments
Afzaal Ahmad Zeeshan 1-Apr-15 4:58am    
Read it, store it. What is difficult or what is the error? Can you share either one of these?
dirtyshooter 1-Apr-15 5:15am    
I am not familiar with EPPlus. If I am able to read the data then every problem is solved.

1 solution

IExcelDataReader and ExcelDataReaderFactory are not part of EPPlus[^], and EPPlus does not support Excel 2003 (.xsl) files.

It sounds like you're using the ExcelDataReader package[^], and you either haven't added the reference to your project, or you're missing a using directive for the Excel namespace.
 
Share this answer
 
Comments
dirtyshooter 2-Apr-15 3:12am    
you got me richard. so,ExcelDataReader is the package i am using. but i am using Excel namespace though. still getting "not found " error.
Richard Deeming 2-Apr-15 7:49am    
So you have added the package to your project, and you have a using Excel; statement at the top of the code file?

If so, it's possible that there's a conflict with a namespace in your application. Try changing the using statement to: using global::Excel;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900