Cannot find central directory error
check weather you are using .xlsx or .xls file.
If you are using .xlsx then use
IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
if you are using .xls then use
IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
Hope it helps. It worked for me.
An exception stating:
Cannot find central directory
indicates that one of the following is likely true:
- The file is corrupt
- The file is not actually an
.xlsx
file (are you sure it isn't an.xls
file?) - The library you're using to read the file has a bug
From your code it looks like you're using ExcelDataReader and attempting to open an XML format (xlsx
) file. Are you sure that the file isn't actually a .xls
file that someone has mis-named as .xlsx
? You could check this by using:
IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
instead of:
IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);