I am using ExcelDataReader library for read excel files in .Net project. When I read ".xls" with CreateBinaryReader everything works fine. But, when I read ".xlsx" with CreateOpenXmlReader throwing "object reference not set to an instance of an object" exception.
using (FileStream excelfile = System.IO.File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read))
{
IExcelDataReader excelReader;
string ftype = Path.GetExtension(excelfile.Name);
if(ftype == “.xls")
excelReader = ExcelReaderFactory.CreateBinaryReader(excelfile,true);
else
excelReader = ExcelReaderFactory.CreateOpenXmlReader(excelfile);
...
}
My ExcelDataReader version is 2.1.2.3 and I can't update. I followed it with debug, but I couldn't detect the problem. What should I do about this problem?
Solved: I had to upgrade and when I edited the changed functions, I read without errors in both file types. I use "CreateReader" function.