I have a date in format \"4/5/2011\" (month/day/year) in a xlsx file in one of the cells. Im trying to parse the file and load those data in some classes.
So far the
I do this after I retrieve any inline string:
private static object Convert(this DocumentFormat.OpenXml.Spreadsheet.CellValues value, string content)
{
switch (value)
{
case DocumentFormat.OpenXml.Spreadsheet.CellValues.Boolean:
if (content.Length < 2)
{
return content?.ToUpperInvariant() == "T" || content == "1";
}
return System.Convert.ToBoolean(content);
case DocumentFormat.OpenXml.Spreadsheet.CellValues.Date:
if (double.TryParse(content, out double result))
{
return System.DateTime.FromOADate(result);
}
return null;
case DocumentFormat.OpenXml.Spreadsheet.CellValues.Number:
return System.Convert.ToDecimal(content);
case DocumentFormat.OpenXml.Spreadsheet.CellValues.Error:
case DocumentFormat.OpenXml.Spreadsheet.CellValues.String:
case DocumentFormat.OpenXml.Spreadsheet.CellValues.InlineString:
case DocumentFormat.OpenXml.Spreadsheet.CellValues.SharedString:
default:
return content;
}
}