I am currently trying to figure out how to iterate through numbered List Items (bullets) and remove them based upon their number (i.e. remove if Bullets number is 2 or 3).
- List Item A
- List Item B
- List Item C
- List Item D
Initially I was trying to iterate the Paragraphs and find those that have a specific ListFormat, but so far haven’t had any luck. I’ve done a good bit of searching on the forums but haven’t found a similar problem to this one.
Hi Patrick,
Thanks for your inquiry. Please use ListFormat.RemoveNumbers method to remove numbers or bullets from the current paragraph and sets list level to zero.
Please use following code example to achieve your requirements. Hope this helps you.
Document doc = new Document(MyDir + "in.docx");
doc.UpdateListLabels();
NodeCollection paras = doc.GetChildNodes(NodeType.Paragraph, true);
foreach (Paragraph para in paras)
{
if (para.ListFormat.IsListItem)
{
ListLabel label = para.ListLabel;
int result;
if (int.TryParse(label.LabelString.Trim().Replace(".", ""), out result))
{
para.ListFormat.RemoveNumbers();
}
}
}
doc.Save(MyDir + "Out.docx");
Tahir — How would this differ if I needed to also delete all of the content associated with the numbered list item?