2

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

2 Answers 2

7

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);

Sign up to request clarification or add additional context in comments.

Comments

3

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.