Last active
May 16, 2024 18:11
-
-
Save fileformat-words-gists/45a28fd403bfc13157e8f937641d80a1 to your computer and use it in GitHub Desktop.
C# Modify Roman Alphabetic Paragraphs in Word Documents
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Prerequisite: Install <a href="https://www.nuget.org/packages/FileFormat.Words">FileFormat.Words</a>. | |
// Load the Word Document | |
var doc = new FileFormat.Words.Document($"WordParagraphsRomanAlphabetic.docx"); | |
// Initialize the body with the document | |
var body = new FileFormat.Words.Body(doc); | |
//foreach (FileFormat.Words.IElements.Paragraph paragraph in body.Paragraphs) | |
foreach (var paragraph in body.Paragraphs) | |
{ | |
if (paragraph.Style == "ListParagraph") | |
{ | |
paragraph.Style = "Normal"; | |
paragraph.AddRun(new FileFormat.Words.IElements.Run | |
{ Text = " (alphabet removed)", Italic = true }); | |
doc.Update(paragraph); | |
} | |
} | |
// Save the modified Word Document | |
doc.Save($"ModifiedDocumnet.docx"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment