Skip to content

Commit b37b543

Browse files
committed
fix:修复@if标签移除的问题
1 parent a27b211 commit b37b543

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

src/MiniWord/MiniWord.Implment.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -779,15 +779,17 @@ private static void ReplaceIfStatements(OpenXmlElement rootXmlElement, List<Open
779779

780780
for (int i = paragraphIfIndex + 1; i <= paragraphEndIfIndex - 1; i++)
781781
{
782-
if(rootXmlElement.ChildElements.Any(c=>c == elementList[i])) rootXmlElement.RemoveChild(elementList[i]);
782+
elementList[i].Remove();
783783
}
784784
}
785-
if(rootXmlElement.ChildElements.Any(c => c == ifP))
786-
rootXmlElement.RemoveChild(ifP);
787-
if (rootXmlElement.ChildElements.Any(c => c == endIfP))
788-
rootXmlElement.RemoveChild(endIfP);
785+
// 从paragraphs中移除,防止死循环
789786
paragraphs.Remove(ifP);
790787
paragraphs.Remove(endIfP);
788+
// 从doc元素移除
789+
if (ifP.Parent != null)
790+
ifP.Remove();
791+
if (endIfP.Parent != null)
792+
endIfP.Remove();
791793
}
792794
}
793795

0 commit comments

Comments
 (0)