Skip to content

Commit

Permalink
Merge pull request #130 from POFerro/develop
Browse files Browse the repository at this point in the history
returns null instead of empty string for blank cells
  • Loading branch information
donnytian committed Nov 3, 2023
2 parents 7ee9651 + 36e09f2 commit 0934a9b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions Npoi.Mapper/src/Npoi.Mapper/MapHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,13 @@ public static bool TryGetCellValue(ICell cell, Type targetType, TrimSpacesType t
value = null;
if (cell == null) return true;

if (targetType == StringType)
var cellType = GetCellType(cell);

if (targetType == StringType && cellType != CellType.Blank)
{
value = TrimString(CellDataFormatter.FormatCellValue(cell, evaluator));
string trimmedValue = TrimString(CellDataFormatter.FormatCellValue(cell, evaluator));
value = trimmedValue?.Length == 0 ? null : trimmedValue;

return true;
}

Expand All @@ -361,7 +365,7 @@ string TrimString(string raw)
}
}

switch (GetCellType(cell))
switch (cellType)
{
case CellType.String:

Expand Down
4 changes: 2 additions & 2 deletions Npoi.Mapper/test/NestedPropertyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ public void ImportWithNestedPropertiesTest()
Assert.AreEqual(addressId, objs[0].Value.Billing.Address.AddressId);
Assert.AreEqual(date.Date, objs[0].Value.Billing.Dates.Dto.Date);

Assert.AreEqual("", objs[1].Value.Name);
Assert.AreEqual(null, objs[1].Value.Name);
Assert.AreEqual(customerAge, objs[1].Value.Age);
Assert.AreEqual("", objs[1].Value.Billing.Contact.Name);
Assert.AreEqual(null, objs[1].Value.Billing.Contact.Name);
Assert.AreEqual(null, objs[1].Value.Billing.Address);
Assert.AreEqual(DateTime.MinValue, objs[1].Value.Billing.Dates.Dto.Date);
}
Expand Down

0 comments on commit 0934a9b

Please sign in to comment.