Skip to content

Commit 4d697fa

Browse files
Fixes formulas not being replaced in templates (#846)
* Copies fix from PR 844 to the main branch * Removing superfluous early call to CleanXml --------- Co-authored-by: Ethan <[email protected]>
1 parent d1a19c9 commit 4d697fa

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/MiniExcel.Core/OpenXml/Templates/OpenXmlTemplate.Impl.cs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -599,11 +599,7 @@ private async Task<GenerateCellValuesContext> GenerateCellValuesAsync(GenerateCe
599599
var isFirst = generateCellValuesContext.isFirst;
600600
var iEnumerableIndex = generateCellValuesContext.iEnumerableIndex;
601601
var currentHeader = generateCellValuesContext.currentHeader;
602-
603-
// Just need to remove space string one time https://github.com/mini-software/MiniExcel/issues/751
604-
var cleanOuterXmlOpen = CleanXml(outerXmlOpen, endPrefix);
605-
var cleanInnerXml = CleanXml(innerXml, endPrefix);
606-
602+
607603
// https://github.com/mini-software/MiniExcel/issues/771 Saving by template introduces unintended value replication in each row #771
608604
var notFirstRowElement = rowElement.Clone();
609605
foreach (XmlElement c in notFirstRowElement.SelectNodes("x:c", Ns))
@@ -612,15 +608,14 @@ private async Task<GenerateCellValuesContext> GenerateCellValuesAsync(GenerateCe
612608
if (v is not null && !NonTemplateRegex.IsMatch(v.InnerText))
613609
v.InnerText = string.Empty;
614610
}
615-
var cleanNotFirstRowInnerXml = CleanXml(notFirstRowElement.InnerXml, endPrefix);
616611

617612
foreach (var item in rowInfo.CellIEnumerableValues)
618613
{
619614
iEnumerableIndex++;
620615
rowXml.Clear()
621-
.Append(cleanOuterXmlOpen)
616+
.Append(outerXmlOpen)
622617
.AppendFormat(@" r=""{0}"">", newRowIndex)
623-
.Append(cleanInnerXml)
618+
.Append(innerXml)
624619
.Replace("{{$rowindex}}", newRowIndex.ToString())
625620
.AppendFormat("</{0}>", row.Name);
626621

@@ -795,7 +790,7 @@ private async Task<GenerateCellValuesContext> GenerateCellValuesAsync(GenerateCe
795790
if (isFirst)
796791
{
797792
// https://github.com/mini-software/MiniExcel/issues/771 Saving by template introduces unintended value replication in each row #771
798-
cleanInnerXml = cleanNotFirstRowInnerXml;
793+
innerXml = notFirstRowElement.InnerXml;
799794
isFirst = false;
800795
}
801796

@@ -804,9 +799,9 @@ private async Task<GenerateCellValuesContext> GenerateCellValuesAsync(GenerateCe
804799

805800
// replace formulas
806801
ProcessFormulas(rowXml, newRowIndex);
807-
await writer.WriteAsync(rowXml.ToString()
802+
await writer.WriteAsync(CleanXml(rowXml, endPrefix).ToString()
808803
#if NET7_0_OR_GREATER
809-
.AsMemory(), cancellationToken
804+
.AsMemory(), cancellationToken
810805
#endif
811806
).ConfigureAwait(false);
812807

0 commit comments

Comments
 (0)