Reading Excel xlsb files in C#

Kaushik Das picture Kaushik Das · Feb 8, 2015 · Viewed 14.2k times · Source

There is a new requirement for my project to read various types of Excel files. I am able to read .xls and .xlsx files using the ExcelDataReader dll from Codeplex. The problem is when I try to read .xlsb files. ExcelDataReader cannot read from .xlsb files. Is there any other efficient way of reading xlsb files apart from using Microsoft.Office.Interop.Excel dll in server based applications .

IExcelDataReader excelReader = fileName.EndsWith(".xlsx")
                                               ? ExcelReaderFactory.CreateOpenXmlReader(stream)
                                               : ExcelReaderFactory.CreateBinaryReader(stream);
while (excelReader.Read())
{
     //myStuff read the file
}

Answer

Rob picture Rob · Feb 8, 2015

LinqToExcel supports xlsb as well as xls and xlsx.

Basic usage of this library looks like this:

using (var excelQueryFactory = new ExcelQueryFactory(filePath))
{
     //access your worksheet LINQ way
     var worksheet = excelQueryFactory.Worksheet("worksheetName").Where(...);
}

More detailed tutorial