Reputation: 457
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();
}
Upvotes: 2
Views: 9588
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
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