Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove from paragraphs to prevent infinite loops #90

Merged
merged 2 commits into from
Nov 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/MiniWord/MiniWord.Implment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ private static object GetObjVal(object objSource, string propNames)
/// <exception cref="Exception"></exception>
private static object GetObjVal(object objSource, string[] propNames)
{
if(objSource == null) return null;

var nextPropNames = propNames.Skip(1).ToArray();
if (objSource is IDictionary)
{
Expand Down Expand Up @@ -777,15 +779,17 @@ private static void ReplaceIfStatements(OpenXmlElement rootXmlElement, List<Open

for (int i = paragraphIfIndex + 1; i <= paragraphEndIfIndex - 1; i++)
{
if(rootXmlElement.ChildElements.Any(c=>c == 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();
}
}

Expand Down
Loading