Skip to content

Commit fd00b32

Browse files
committed
FIX:没有循环数据时,删除@foreach-@endforeach之间的元素
1 parent 1e84b58 commit fd00b32

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/MiniWord/MiniWord.Implment.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,8 @@ private static void ReplaceForeachStatements(OpenXmlElement xmlElement,Wordproce
666666
var copyLoopEles = betweenEles.Select(e => e.CloneNode(true)).ToList();
667667
// 需要循环的数据
668668
var foreachList = GetObjVal(data, foreachDataKey);
669-
if (foreachList is IList list)
669+
670+
if (foreachList is IList list && list.Count > 0)
670671
{
671672
var loopEles = new List<OpenXmlElement>();
672673
for (var i = 0; i < list.Count; i++)
@@ -703,6 +704,14 @@ private static void ReplaceForeachStatements(OpenXmlElement xmlElement,Wordproce
703704
}
704705
}
705706
}
707+
else
708+
{
709+
// 如果没有数据,删除循环元素
710+
foreach (var ele in betweenEles)
711+
{
712+
ele.Remove();
713+
}
714+
}
706715

707716
betweenEles = GetBetweenElements(xmlElement, beginKey, endKey, false);
708717
}

0 commit comments

Comments
 (0)