I am using http://exceldatareader.codeplex.com/. I have an Excel file with a column having dates i.e. D/M/Y. I am trying to read this file using this code:
FileStream stream = File.Open(FilePath, FileMode.Open, FileAccess.Read);
IExcelDataReader excelReader = null;
lock (LockToReadExcelFile)
{
if (FilePath.EndsWith(".xls", true, System.Globalization.CultureInfo.InvariantCulture))
{
excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
}
else if (FilePath.EndsWith(".xlsx", true, System.Globalization.CultureInfo.InvariantCulture))
{
excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
}
else
{
return;
}
}
Then adding it to DataSet as follows:
excelReader.IsFirstRowAsColumnNames = false;
DataSet excelDataTable = excelReader.AsDataSet();
It return rows in {System.DateTime}
object. I want them to parse the dates data in System.String
format.(e.g. Date 7/11/2015 is returned as 7/11/2015 12:00:00 AM {System.DateTime}
.)
PS: I have tried excelReader.AsDataSet(false);
as well but it yields same.