Skip to content

Instantly share code, notes, and snippets.

View fileformat-words-gists's full-sized avatar

fileformat-words-gists

View GitHub Profile
@fileformat-words-gists
fileformat-words-gists / Modify-Multiple-Frame-Paragraphs.cs
Created July 9, 2024 18:04
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)
{
@fileformat-words-gists
fileformat-words-gists / Read-Multiple-Frame-Paragraphs.cs
Created July 9, 2024 18:00
C# Read 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);
// Traverse and display paragraphs with plain text
foreach (var paragraph in body.Paragraphs)
{
System.Console.WriteLine($" Paragraph Text: {paragraph.Text}");
@fileformat-words-gists
fileformat-words-gists / Create-Multiple-Frame-Paragraphs.cs
Created July 9, 2024 17:57
C# Create Multiple Frame Paragraphs in Word Documents
// Prerequisite: Install <a href="https://www.nuget.org/packages/FileFormat.Words">FileFormat.Words</a>.
// Initialize a new word document with the default template
var doc = new FileFormat.Words.Document();
System.Console.WriteLine("Word Document with default template initialized");
// Initialize the body with the new document
var body = new FileFormat.Words.Body(doc);
System.Console.WriteLine("Body of the Word Document initialized");
@fileformat-words-gists
fileformat-words-gists / Modify-Multiple-Multilevel-List-Paragraphs.cs
Last active May 16, 2024 20:39
C# Modify Multiple Multilevel List 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($"MultilevelLists.docx");
// Initialize the body with the document
var body = new FileFormat.Words.Body(doc);
foreach (var paragraph in body.Paragraphs)
{
@fileformat-words-gists
fileformat-words-gists / Read-Multiple-Multilevel-List-Paragraphs.cs
Last active May 16, 2024 18:12
C# Read Multiple Multilevel List 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($"MultilevelLists.docx");
// Initialize the body with the document
var body = new FileFormat.Words.Body(doc);
//System.Collections.Generic.List<FileFormat.Words.IElements.Paragraph>
// paragraphs = body.Paragraphs;
@fileformat-words-gists
fileformat-words-gists / Create-Multiple-Multilevel-List-Paragraphs.cs
Created May 16, 2024 17:45
C# Create Multiple Multilevel List Paragraphs in Word Documents
// Prerequisite: Install <a href="https://www.nuget.org/packages/FileFormat.Words">FileFormat.Words</a>.
// The resulting docx document should be like this: https://i.imgur.com/6PKIb56.png
// Initialize docx document
FileFormat.Words.Document doc = new FileFormat.Words.Document();
System.Console.WriteLine("Word Document with default template initialized");
// Initialize document body
var body = new FileFormat.Words.Body(doc);
@fileformat-words-gists
fileformat-words-gists / Modify-Roman-Alphabetic-Paragraphs.cs
Last active May 16, 2024 18:11
C# Modify Roman Alphabetic 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($"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)
@fileformat-words-gists
fileformat-words-gists / Read-Roman-Alphabetic-Paragraphs.cs
Last active May 16, 2024 18:09
C# Read Roman Alphabetic 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($"WordParagraphsRomanAlphabetic.docx");
// Initialize the body with the document
var body = new FileFormat.Words.Body(doc);
//System.Collections.Generic.List<FileFormat.Words.IElements.Paragraph>
// paragraphs = body.Paragraphs;
@fileformat-words-gists
fileformat-words-gists / Create-Roman-Alphabetic-Paragraphs.cs
Last active May 16, 2024 18:06
C# Create Roman Alphabetic Paragraphs in Word Documents
// Prerequisite: Install <a href="https://www.nuget.org/packages/FileFormat.Words">FileFormat.Words</a>.
// Initialize docx document
FileFormat.Words.Document doc = new FileFormat.Words.Document();
System.Console.WriteLine("Word Document with default template initialized");
// Initialize document body
var body = new FileFormat.Words.Body(doc);
System.Console.WriteLine("Body of the Word Document initialized");
@fileformat-words-gists
fileformat-words-gists / Modify-Numbered-Word-Paragraphs.cs
Last active May 16, 2024 18:03
C# Modify Numbered 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($"WordParagraphsNumbered.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)