Wednesday, April 27, 2011

ExcelDataReader to read excel

ExcelDataReader is a Lightweight library used for reading Microsoft Excel files in .NET.

This Dll will avoid lot of overhead which you may face during Excel operation in your .NET project.

First download the dll using the link, ExcelDataReader DLL Download

Then use below code,
FileStream stream = File.Open(filePath, FileMode.Open, FileAccess.Read);
  
 IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
  
 IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
  
 DataSet result = excelReader.AsDataSet();
  
 excelReader.IsFirstRowAsColumnNames = true;
  
 DataSet result = excelReader.AsDataSet();
  
 while (excelReader.Read())
 {
   //excelReader.GetInt32(0);
 }
 excelReader.Close();  

No comments: