List<int> tempi = new List<int>(); for (int i = 0; i < doc.BodyElements.Count; i++) { //在这里删除的是段落,也可以其它类型的,如图片 if (doc.BodyElements[i] is XWPFParagraph) { XWPFParagraph temp = (XWPFParagraph)doc.BodyElements[i]; if (temp != null && temp.ParagraphText == "$[lqwvje]$") { tempi.Add(i); } } } for (int i = tempi.Count - 1; i >= 0; i--) { //因为删除一个,他们的索引就会发生变化,所以从索引大的开始删除 //本文来自 www.luofenming.com doc.RemoveBodyElement(tempi[i]); }
本文来自www.LuoFenMing.com