Created
June 12, 2024 12:23
-
-
Save openize-words-gists/08e214d1abbf7603657d9b42e3ed9822 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/Openize.Words">Openize.Words</a>. | |
// Load the Word Document | |
var doc = new Openize.Words.Document($"WordParagraphsFrame.docx"); | |
var body = new Openize.Words.Body(doc); | |
foreach (var paragraph in body.Paragraphs) | |
{ | |
if (paragraph.ParagraphBorder.Size > 0) | |
{ | |
paragraph.ParagraphBorder.Width = Openize.Words.IElements.BorderWidth.Single; | |
paragraph.ParagraphBorder.Color = Openize.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