From b37b543278daa6d7489f5cbe97647c35395e0ecc Mon Sep 17 00:00:00 2001 From: wx Date: Wed, 30 Oct 2024 08:24:40 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D@if=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=E7=A7=BB=E9=99=A4=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MiniWord/MiniWord.Implment.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/MiniWord/MiniWord.Implment.cs b/src/MiniWord/MiniWord.Implment.cs index 3ef1148..da59c6f 100644 --- a/src/MiniWord/MiniWord.Implment.cs +++ b/src/MiniWord/MiniWord.Implment.cs @@ -779,15 +779,17 @@ private static void ReplaceIfStatements(OpenXmlElement rootXmlElement, Listc == elementList[i])) rootXmlElement.RemoveChild(elementList[i]); + elementList[i].Remove(); } } - if(rootXmlElement.ChildElements.Any(c => c == ifP)) - rootXmlElement.RemoveChild(ifP); - if (rootXmlElement.ChildElements.Any(c => c == endIfP)) - rootXmlElement.RemoveChild(endIfP); + // 从paragraphs中移除,防止死循环 paragraphs.Remove(ifP); paragraphs.Remove(endIfP); + // 从doc元素移除 + if (ifP.Parent != null) + ifP.Remove(); + if (endIfP.Parent != null) + endIfP.Remove(); } }