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 / Create-Word-Paragraphs.cs
Last active December 21, 2023 01:27
C# Create Word Document Paragraphs
/// <summary>
/// Creates a new Word Document with structured content using
/// <a href="https://www.nuget.org/packages/FileFormat.Words">FileFormat.Words</a>.
/// Generates paragraphs with heading styles defined by the Word document template.
/// Adds normal paragraphs under each heading paragraph, including text runs with various fonts as per the template.
/// Saves the newly created Word Document.
/// </summary>
/// <param name="documentDirectory">
/// The directory where the Word Document will be saved (default is the root of your project).
/// </param>
@fileformat-words-gists
fileformat-words-gists / Read-Word-Paragraphs.cs
Last active December 16, 2023 17:49
C# Read Word Document Paragraphs
/// <summary>
/// Loads a Word Document with structured content using
/// <a href="https://www.nuget.org/packages/FileFormat.Words">FileFormat.Words</a>.
/// Traverses paragraphs and displays associated styles as defined by the Word document template.
/// Traverses through each run (text fragment) within each paragraph and displays fragment values.
/// </summary>
/// <param name="documentDirectory">
/// The directory where the Word Document to load is present
/// (default is the root of your project).
/// </param>
@fileformat-words-gists
fileformat-words-gists / Modify-Word-Paragraphs.cs
Last active December 16, 2023 17:50
C# Modify Word Document Paragraphs
/// <summary>
/// Loads a Word Document with structured content using
/// <a href="https://www.nuget.org/packages/FileFormat.Words">FileFormat.Words</a>.
/// Modifies paragraphs by prepending 'Modified Heading :' for styled paragraphs
/// and 'Modified Run :' for each run within normal paragraphs, preserving the existing format.
/// 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 the the root of your project).
@fileformat-words-gists
fileformat-words-gists / Create-Word-Images.cs
Last active December 16, 2023 17:51
C# Create Word Document Images
/// <summary>
/// Creates a new Word Document with structured content using
/// <a href="https://www.nuget.org/packages/FileFormat.Words">FileFormat.Words</a>.
/// Loads images from the specified diretory and decodes using SkiaSharp.
/// Creates a word document, appends loaded images and then saves the word document.
/// </summary>
/// <param name="documentDirectory">
/// The directory where the Word Document will be saved (default is root of your project).
/// </param>
/// <param name="imageDirectory">
@fileformat-words-gists
fileformat-words-gists / Read-Word-Images.cs
Last active December 16, 2023 17:52
C# Read Word Document Images
/// <summary>
/// Loads a Word Document with structured content using
/// <a href="https://www.nuget.org/packages/FileFormat.Words">FileFormat.Words</a>.
/// Traverses images and displays image metadata.
/// </summary>
/// <param name="documentDirectory">
/// The directory where the Word Document to load is present (default is root of your project).
/// </param>
/// <param name="filename">
/// The name of the Word Document file to load (default is "WordImages.docx").
@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).
@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 / 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 / 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 / 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