Skip to content

Commit

Permalink
FIX:没有循环数据时,删除@foreach-@endforeach之间的元素
Browse files Browse the repository at this point in the history
  • Loading branch information
wangx036 committed Sep 27, 2024
1 parent 1e84b58 commit fd00b32
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/MiniWord/MiniWord.Implment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,8 @@ private static void ReplaceForeachStatements(OpenXmlElement xmlElement,Wordproce
var copyLoopEles = betweenEles.Select(e => e.CloneNode(true)).ToList();
// 需要循环的数据
var foreachList = GetObjVal(data, foreachDataKey);
if (foreachList is IList list)

if (foreachList is IList list && list.Count > 0)
{
var loopEles = new List<OpenXmlElement>();
for (var i = 0; i < list.Count; i++)
Expand Down Expand Up @@ -703,6 +704,14 @@ private static void ReplaceForeachStatements(OpenXmlElement xmlElement,Wordproce
}
}
}
else
{
// 如果没有数据,删除循环元素
foreach (var ele in betweenEles)
{
ele.Remove();
}
}

betweenEles = GetBetweenElements(xmlElement, beginKey, endKey, false);
}
Expand Down

0 comments on commit fd00b32

Please sign in to comment.