We are facing issue with date in .xls file.When we read the file using ExcelReaderFactory.CreateBinaryReader() all the dates availed in excel file converting to a number.
Dll version we are using is 2.1.2.0
How can we solve this issue any idea?
Check the attachment to get better idea.
code we used :
public DataTable getDataTableOfExcel(Stream stream, string filename, bool IsFirstRowHasHeader)
{
try
{
IExcelDataReader excelReader = null;
FileInfo fileInfo = new FileInfo(filename);
if (fileInfo.Extension.ToLower().Equals(".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);
excelReader.IsFirstRowAsColumnNames = IsFirstRowHasHeader;
DataSet ds = excelReader.AsDataSet();
DataTable dt = ds.Tables[0].Copy();
return dt;
}
catch (Exception ex)
{
Logger.logError(logforimportrecipients, ex);
throw ex;
}
}
Comments: ** Comment from web user: DanielRousseau **
I think you can solve your problem by either
a) using the following method from ExcelReaderFactory to create the binary reader:
```
public static IExcelDataReader CreateBinaryReader(Stream fileStream, bool convertOADate)
```
with convertOADate set to true.
OR
b) retrieving the data set using method
```
/// <summary>
///Read all data in to DataSet and return it
/// </summary>
/// <param name="convertOADateTime">if set to <c>true</c> [try auto convert OA date time format].</param>
/// <returns>The DataSet</returns>
DataSet AsDataSet(bool convertOADateTime);
```
again with convertOADateTime set to true.