You are getting the error because
4th Column
in the Excel is a
Date
type Column
Excel Cells
Mininum
Date Value is
01/01/1900
So when you are trying to insert a date value which is less than
1900
, it will
throw an exception
You can validate the date value as below
_worksheet.Cells[rowCounter, 4] = GetExcelValidDate (instance.dob);
For Date Column:
private static DateTime? GetExcelValidDate(DateTime? date)
{
DateTime? temp = null;
if (date.HasValue)
temp = date.Value.Year < 1900 ? temp : date;
return temp;
}
To convert it as text column
private static string GetExcelValidDate(DateTime? date)
{
string temp = null;
if (date.HasValue)
temp = date.Value.ToString("MM/dd/YYYY");
return temp;
}