neo
neo

Reputation: 457

ExcelDataReader not reading the xls file in some cases

When using excelDatareader for some Excel file the ExcelReaderFactory.CreateOpenXmlReader(stream) is returning null and not taking the filestream. But for some excel file it is running perfect.

Can somebody explain me the reason?

static void Main(string[] args)
{
    FileStream stream = File.Open(@"C:\Users\nichi-user\Desktop\BLRJCCI.xls", FileMode.Open, FileAccess.Read);

    IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);

    DataSet result = excelReader.AsDataSet();

    result.Tables[0].TableName.ToString();
}

enter image description here

Upvotes: 2

Views: 9588

Answers (2)

Johan Appelgren
Johan Appelgren

Reputation: 341

ExcelDataReader can in most cases detect what type of file it is if you use ExcelReaderFactory.CreateReader instead. See https://github.com/ExcelDataReader/ExcelDataReader for supported formats and versions.

Upvotes: 3

gery128
gery128

Reputation: 96

Excel can be of two types: -Binary (MS Excel 2003 and older versions - .xls) -Zip - based on Open Office XML standards (MS Excel 2007 onwards - .xlsx)

You should try to use following for older excel format files:

ExcelReaderFactory.CreateBinaryReader(fileStream);

Upvotes: 7

Related Questions