Skip to content

Commit 57de2a5

Browse files
authored
Merge pull request #90 from wangx036/main
2个BUG修复
2 parents 3428cbd + b37b543 commit 57de2a5

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/MiniWord/MiniWord.Implment.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ private static object GetObjVal(object objSource, string propNames)
202202
/// <exception cref="Exception"></exception>
203203
private static object GetObjVal(object objSource, string[] propNames)
204204
{
205+
if(objSource == null) return null;
206+
205207
var nextPropNames = propNames.Skip(1).ToArray();
206208
if (objSource is IDictionary)
207209
{
@@ -777,15 +779,17 @@ private static void ReplaceIfStatements(OpenXmlElement rootXmlElement, List<Open
777779

778780
for (int i = paragraphIfIndex + 1; i <= paragraphEndIfIndex - 1; i++)
779781
{
780-
if(rootXmlElement.ChildElements.Any(c=>c == elementList[i])) rootXmlElement.RemoveChild(elementList[i]);
782+
elementList[i].Remove();
781783
}
782784
}
783-
if(rootXmlElement.ChildElements.Any(c => c == ifP))
784-
rootXmlElement.RemoveChild(ifP);
785-
if (rootXmlElement.ChildElements.Any(c => c == endIfP))
786-
rootXmlElement.RemoveChild(endIfP);
785+
// 从paragraphs中移除,防止死循环
787786
paragraphs.Remove(ifP);
788787
paragraphs.Remove(endIfP);
788+
// 从doc元素移除
789+
if (ifP.Parent != null)
790+
ifP.Remove();
791+
if (endIfP.Parent != null)
792+
endIfP.Remove();
789793
}
790794
}
791795

0 commit comments

Comments
 (0)