Skip to content

Commit 695c50e

Browse files
committed
add unit test #771
1 parent 04cf552 commit 695c50e

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/MiniExcel/SaveByTemplate/ExcelOpenXmlTemplate.Impl.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,14 +534,18 @@ private void CellIEnumerableValuesGenerate(string endPrefix, StreamWriter writer
534534
var cleanRowXml = CleanXml(rowXml, endPrefix);
535535
var cleanOuterXmlOpen = CleanXml(outerXmlOpen, endPrefix);
536536
var cleanInnerXml = CleanXml(innerXml, endPrefix);
537-
var notFirstRowInnerXmlElement = rowElement.Clone();
537+
538+
// https://github.com/mini-software/MiniExcel/issues/771 Saving by template introduces unintended value replication in each row #771
539+
var notFirstRowInnerXmlElement = rowElement.Clone();
538540
foreach (XmlElement c in notFirstRowInnerXmlElement.SelectNodes("x:c", _ns))
539541
{
540542
var v = c.SelectSingleNode("x:v", _ns);
541543
if (v != null && !Regex.IsMatch(v.InnerText, @".*?\{\{.*?\}\}.*?"))
542544
v.InnerText = string.Empty;
543545
}
544546
var cleannotFirstRowInnerXmlElementInnerXml = CleanXml(notFirstRowInnerXmlElement.InnerXml, endPrefix);
547+
548+
545549
foreach (var item in rowInfo.CellIEnumerableValues)
546550
{
547551
iEnumerableIndex++;
@@ -716,7 +720,10 @@ private void CellIEnumerableValuesGenerate(string endPrefix, StreamWriter writer
716720
rowIndexDiff += rowInfo.IEnumerableMercell?.Height ?? 1; //TODO:base on the merge size
717721
if (isFirst)
718722
{
723+
// https://github.com/mini-software/MiniExcel/issues/771 Saving by template introduces unintended value replication in each row #771
719724
cleanInnerXml = cleannotFirstRowInnerXmlElementInnerXml;
725+
726+
720727
isFirst = false;
721728
}
722729

tests/MiniExcelTests/MiniExcelIssueTests.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4220,5 +4220,10 @@ public void TestIssue771()
42204220
list12 = Enumerable.Range(0, 3).Select(s => new { ID = Guid.NewGuid(), level = s }),
42214221
};
42224222
MiniExcel.SaveAsByTemplate(path,template, value);
4223+
var rows = MiniExcel.Query(path).ToList();
4224+
Assert.Equal("2025-1", rows[2].B);
4225+
Assert.Equal(null, rows[3].B);
4226+
Assert.Equal(null, rows[4].B);
4227+
Assert.Equal("2025-2", rows[5].B);
42234228
}
42244229
}

0 commit comments

Comments
 (0)