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 / Read-Word-Paragraph-Indent.cs
Last active March 3, 2024 10:36
C# Read Word Paragraph Indent
// 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);
System.Collections.Generic.List<FileFormat.Words.IElements.Paragraph>
paragraphs = body.Paragraphs;
@fileformat-words-gists
fileformat-words-gists / Create-Word-Paragraph-Indent.cs
Created March 3, 2024 10:17
C# Create Word Paragraph Indent
// 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-Word-Paragraph-Alignment.cs
Last active April 22, 2024 07:34
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)
{
@fileformat-words-gists
fileformat-words-gists / Read-Word-Paragraph-Alignment.cs
Last active March 3, 2024 10:38
C# Read 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);
System.Collections.Generic.List<FileFormat.Words.IElements.Paragraph>
paragraphs = body.Paragraphs;
@fileformat-words-gists
fileformat-words-gists / Create-Word-Paragraph-Alignment.cs
Last active April 22, 2024 07:33
C# Create Word Paragraph Alignment
// 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 / concurrent-processing-documents.cs
Created December 20, 2023 22:18
Multiple Word Documents Concurrent Updating in C#
// Concurrently updating three documents using <a href="https://www.nuget.org/packages/FileFormat.Words">FileFormat.Words</a>
// Supported in v23.12.0
var task1 = System.Threading.Tasks.Task.Run(()
=> ManipulateDocument("doc1.docx", "doc1_Threaded.docx"));
var task2 = System.Threading.Tasks.Task.Run(()
=> ManipulateDocument("doc2.docx", "doc2_Threaded.docx"));
var task3 = System.Threading.Tasks.Task.Run(()
=> ManipulateDocument("doc3.docx", "doc3_Threaded.docx"));
// Wait for all tasks to complete
@fileformat-words-gists
fileformat-words-gists / Modify-Word-Tables.cs
Last active December 16, 2023 17:55
C# Modify Words Document Tables
/// <summary>
/// Loads a Word Document with structured content using
/// <a href="https://www.nuget.org/packages/FileFormat.Words">FileFormat.Words</a>.
/// Modifies tables by setting column widths to 2000
/// Saves the modified Word Document.
/// </summary>
/// <param name="documentDirectory">
/// The directory where the Word Document to load is present and
/// the modified document will be saved (default is root of your project).
/// </param>
@fileformat-words-gists
fileformat-words-gists / Read-Word-Tables.cs
Last active December 16, 2023 17:54
C# Read Word Document Tables
/// <summary>
/// Loads a Word Document with structured content using
/// <a href="https://www.nuget.org/packages/FileFormat.Words">FileFormat.Words</a>.
/// Traverses tables and displays associated styles as defined by the Word document template.
/// Traverses through each row and then traverses columns within the row.
/// Traverses through paragrpahs within each cell and displays paragraph plain text
/// </summary>
/// <param name="documentDirectory">
/// The directory where the Word Document to load is present
/// (default is root of your project).
@fileformat-words-gists
fileformat-words-gists / Create-Word-Tables.cs
Last active December 21, 2023 01:27
C# Create Word Document Tables
/// <summary>
/// Creates a new Word Document with structured content using
/// <a href="https://www.nuget.org/packages/FileFormat.Words">FileFormat.Words</a>.
/// Generates 5(rows) x 3(cols) tables with table styles defined by the Word document template.
/// Appends each table to the body of the word document.
/// Saves the newly created word document.
/// </summary>
/// <param name="documentDirectory">
/// The directory where the Word Document will be saved (default is root of your project).
/// </param>
@fileformat-words-gists
fileformat-words-gists / Modify-Word-Images.cs
Last active December 16, 2023 17:53
C# Modify Word Document Images
/// <summary>
/// Loads a Word Document with structured content using
/// <a href="https://www.nuget.org/packages/FileFormat.Words">FileFormat.Words</a>.
/// Gets images from the word document. Decodes image using SkiaSharp and encode to JPG.
/// Resize image to 250(height) and 200(width).
/// Saves the modified Word Document.
/// </summary>
/// <param name="documentDirectory">
/// The directory where the Word Document to load is present and
/// the modified document will be saved (default is root of your project).