Created
July 9, 2024 18:04
-
-
Save fileformat-words-gists/8354a38816cd4edf123b4ff419049eca to your computer and use it in GitHub Desktop.
C# Modify Multiple Frame 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($"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