Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save fileformat-words-gists/bc539ee85e5ad873ed27c5d1c7ff41b2 to your computer and use it in GitHub Desktop.
Save fileformat-words-gists/bc539ee85e5ad873ed27c5d1c7ff41b2 to your computer and use it in GitHub Desktop.
C# Modify Word Paragraph Alignment
// Prerequisite: Install <a href="https://www.nuget.org/packages/FileFormat.Words">FileFormat.Words</a>.
// Load the Word Document
var doc = new FileFormat.Words.Document($"filename.docx");
// Initialize the body with the document
var body = new FileFormat.Words.Body(doc);
foreach (FileFormat.Words.IElements.Paragraph paragraph in body.Paragraphs)
{
paragraph.AddRun(new FileFormat.Words.IElements.Run
{ Text = " (alignment modified to justify)", Italic=true });
paragraph.Alignment = FileFormat.Words.IElements.ParagraphAlignment.Justify; //"Justify";
doc.Update(paragraph);
}
// Save the modified Word Document
doc.Save($"AlignmentModified.docx");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment