Skip to content
This repository has been archived by the owner on Feb 20, 2021. It is now read-only.

Commit

Permalink
Fixed custom formatted datetime parse problem
Browse files Browse the repository at this point in the history
  • Loading branch information
aydin.eraydin committed Feb 26, 2018
1 parent 8e82210 commit 07d2259
Show file tree
Hide file tree
Showing 3 changed files with 256 additions and 244 deletions.
33 changes: 11 additions & 22 deletions src/EPPlus.Core.Extensions/ExcelTableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,17 @@ private static void TrySetProperty(object item, PropertyInfo property, object ce

if (type == typeof(DateTime))
{
DateTime d = DateTime.Parse(cell.ToString());
if (!DateTime.TryParse(cell.ToString(), out DateTime parsedDate))
{
parsedDate = DateTime.FromOADate((double)cell);
}

itemType.InvokeMember(
property.Name,
BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty,
null,
item,
new object[] { d });
new object[] { parsedDate });

return;
}
Expand Down Expand Up @@ -300,26 +303,12 @@ private static void TrySetProperty(object item, PropertyInfo property, object ce

if (type.IsNumeric())
{
if (cell.GetType() == typeof(DateTime))
{
double newVal = ((DateTime)cell).ToOADate();

itemType.InvokeMember(
property.Name,
BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty,
null,
item,
new object[] { newVal });
}
else
{
itemType.InvokeMember(
property.Name,
BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty,
null,
item,
new object[] { Convert.ChangeType(cell, type) });
}
itemType.InvokeMember(
property.Name,
BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty,
null,
item,
new object[] { Convert.ChangeType(cell, type) });
}
}
}
Expand Down
Loading

0 comments on commit 07d2259

Please sign in to comment.