Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save fileformat-words-gists/8354a38816cd4edf123b4ff419049eca to your computer and use it in GitHub Desktop.
Save fileformat-words-gists/8354a38816cd4edf123b4ff419049eca to your computer and use it in GitHub Desktop.
C# Modify Multiple Frame 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($"WordParagraphsFrame.docx");
var body = new FileFormat.Words.Body(doc);
foreach (var paragraph in body.Paragraphs)
{
if (paragraph.ParagraphBorder.Size > 0)
{
paragraph.ParagraphBorder.Width = FileFormat.Words.IElements.BorderWidth.Single;
paragraph.ParagraphBorder.Color = FileFormat.Words.IElements.Colors.Black;
foreach (var run in paragraph.Runs)
{
// Modified paragraph text
run.Text = "Paragraph border modified to single width with black color";
}
System.Console.WriteLine("Frames/Borders changed to single width with black color");
}
// Update the paragraph in the document
doc.Update(paragraph);
}
// Save the modified Word Document
doc.Save($"ModifiedParagraphsFrame.docx");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment