Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save fileformat-words-gists/6abca4875309fac7605518ac368de4c2 to your computer and use it in GitHub Desktop.
Save fileformat-words-gists/6abca4875309fac7605518ac368de4c2 to your computer and use it in GitHub Desktop.
C# Modify Multiple Multilevel List Paragraphs in Word Documents
// Prerequisite: Install <a href="https://www.nuget.org/packages/FileFormat.Words">FileFormat.Words</a>.
// Load the Word Document
var doc = new FileFormat.Words.Document($"MultilevelLists.docx");
// Initialize the body with the document
var body = new FileFormat.Words.Body(doc);
foreach (var paragraph in body.Paragraphs)
{
if (paragraph.Style == "ListParagraph")
{
paragraph.IsNumbered = true;
paragraph.AddRun(new FileFormat.Words.IElements.Run
{ Text = " (numbering type changed to numeric)", Italic = true });
doc.Update(paragraph);
}
}
// Save the modified Word Document
doc.Save($"ModifiedMultilevelLists.docx");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment