Lightweight and fast library written in C# for reading Microsoft Excel files
C# Other
Latest commit c3b50c7 Jul 19, 2016 @wizardgsz wizardgsz committed on GitHub Merge pull request #136 from wizardgsz/develop
Removed wrong ELSE IF, should be IF
Permalink
Failed to load latest commit information.
.nuget Add portable library and restructure projects Sep 4, 2014
BuildProcessTemplates initial creation Jul 31, 2014
Excel.4.5 Create reader based from the file signature Oct 6, 2015
Excel.Tests.4.5 Closes #70 May 21, 2015
Excel.Tests No longer uses the Field<> extension method since it requires .NET 4.… Jun 9, 2016
Excel Merge pull request #136 from wizardgsz/develop Jul 19, 2016
ExcelDataReader.Android Add portable library and restructure projects Sep 4, 2014
ExcelDataReader.Desktop Changes from pull request =into portable library. Dec 16, 2014
ExcelDataReader.Portable Made the same changes as in #123 to the portable code too. Jun 8, 2016
ExcelDataReader.Silverlight Add portable library and restructure projects Sep 4, 2014
ExcelDataReader.iOS Add portable library and restructure projects Sep 4, 2014
Lib Add portable library and restructure projects Sep 4, 2014
NuGetBin initial creation Jul 31, 2014
Silverlight initial creation Jul 31, 2014
TestApp closes #55 Mar 2, 2015
output initial creation Jul 31, 2014
.gitignore Initial commit Jul 25, 2014
Excel.Test.20.testsettings initial creation Jul 31, 2014
Excel.Test.4.5.vsmdi initial creation Jul 31, 2014
Excel.Test.sln initial creation Jul 31, 2014
Excel.Test.vsmdi initial creation Jul 31, 2014
Excel.testsettings initial creation Jul 31, 2014
ExcelDataReader.2.1.2.1.nupkg initial creation Jul 31, 2014
ExcelDataReader.sln Create ExcelDataReader.Desktop Sep 4, 2014
LICENSE Initial commit Jul 25, 2014
README.md Update README.md comments Jan 22, 2016
portable_reademe.md Create ExcelDataReader.Desktop Sep 4, 2014
test.runsettings ExcelOpenXmlReader remove check applyNumberFormat when deciding if to… Nov 28, 2014

README.md

ExcelDataReader

Lightweight and fast library written in C# for reading Microsoft Excel files

This project has just migrated from CodePlex - as is. Please feel free to fork and submit pull requests.

Note Please try the latest source from the repo before reporting issues as there have been recent changes. Also, if you are reporting an issue it is really useful if you can supply an example excel file as this makes debugging much easier and without it we may not be able to resolve any problems.

This project is using a git-flow style workflow so please submit pull requests to the develop branch if possible.

Finding the binaries

It is recommended to use Nuget

Install-Package ExcelDataReader

The current binaries are still on the codeplex site, but these will not be updated going forward. If there are enough requests for separate binary hosting other than nuget then we'll come up with some other solution.

How to use

C# code :

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

//Choose one of either 1 or 2
//1. Reading from a binary Excel file ('97-2003 format; *.xls)
IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream);

//2. Reading from a OpenXml Excel file (2007 format; *.xlsx)
IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);

//Choose one of either 3, 4, or 5
//3. DataSet - The result of each spreadsheet will be created in the result.Tables
DataSet result = excelReader.AsDataSet();

//4. DataSet - Create column names from first row
excelReader.IsFirstRowAsColumnNames = true;
DataSet result = excelReader.AsDataSet();

//5. Data Reader methods
while (excelReader.Read())
{
    //excelReader.GetInt32(0);
}

//6. Free resources (IExcelDataReader is IDisposable)
excelReader.Close();

VB.NET Code:

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

'1. Reading from a binary Excel file ('97-2003 format; *.xls)
Dim excelReader As IExcelDataReader = ExcelReaderFactory.CreateBinaryReader(stream)

'2. Reading from a OpenXml Excel file (2007 format; *.xlsx)
Dim excelReader As IExcelDataReader = ExcelReaderFactory.CreateOpenXmlReader(stream)

'3. DataSet - The result of each spreadsheet will be created in the result.Tables
Dim result As DataSet = excelReader.AsDataSet()

'4. DataSet - Create column names from first row
excelReader.IsFirstRowAsColumnNames = True
Dim result As DataSet = excelReader.AsDataSet()

'5. Data Reader methods
While excelReader.Read()
    'excelReader.GetInt32(0);
End While

'6. Free resources (IExcelDataReader is IDisposable)
excelReader.Close()

Tips

  • SQL reporting services. Set ReadOption.Loose in the CreateBinaryReader factory method to skip some bounds checking which was causing SSRS generated xls to fail. (Only on changeset >= 82970)