Skip to content

Commit

Permalink
Fixed issue #428
Browse files Browse the repository at this point in the history
  • Loading branch information
JanKallman committed Jul 6, 2021
1 parent 85c1fb7 commit 96ae436
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/EPPlus/Style/XmlAccess/ExcelNumberFormatXml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -509,18 +509,18 @@ private void ToNetFormat(string ExcelFormat, bool forColWidth)
//Add qoutes
if (DataType == eFormatType.DateTime) SetDecimal(lstDec, sb); //Remove?

// AM/PM format
if (containsAmPm)
{
format += "tt";
}


if (format == "")
format = sb.ToString();
else
text = sb.ToString();

// AM/PM format
if (containsAmPm)
{
format += "tt";
}

if (forColWidth)
{
NetFormatForWidth = format;
Expand Down
13 changes: 13 additions & 0 deletions src/EPPlusTest/WorkSheetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1696,6 +1696,19 @@ public void Text()
Assert.AreEqual("2018", ws.Cells["A1"].Text);
}
}
[TestMethod]
public void ValudateDateTextWithAMPM()
{
using (var package = new ExcelPackage())
{
var ws = package.Workbook.Worksheets.Add("dateText");
ws.Cells["A1"].Value = new DateTime(2021, 7, 6, 9, 29, 0);
ws.Cells["A1"].Style.Numberformat.Format = "[$-0409]M/d/yyyy h:mm AM/PM";

Assert.AreEqual("7/6/2021 9:29 AM", ws.Cells["A1"].Text);
}
}

[TestMethod]
public void CopyWorkSheetWithInsertInSharedFormula()
{
Expand Down

0 comments on commit 96ae436

Please sign in to comment.