IExcelDataReader excelReader;
if (Path.GetExtension(strExcelFile) == ".xls")
{
//1. Reading from a binary Excel file ('97-2003 format; *.xls)
excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
}
else
{
//2. Reading from a OpenXml Excel file (2007 format; *.xlsx)
excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
} DataSet result = excelReader.AsDataSet();
excelReader.Close();
stream.Close(); return result.Tables[0];