Skip to content

Instantly share code, notes, and snippets.

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

Openize Words Gists openize-words-gists

View GitHub Profile
@openize-words-gists
openize-words-gists / Create-Word-Paragraphs.cs
Created May 22, 2024 12:35
C# Create Word Document Paragraphs
//Prerequisite: Install <a href="https://www.nuget.org/packages/Openize.Words">Openize.Words</a>.
// Initialize a new word document with the default template
var doc = new Openize.Words.Document();
System.Console.WriteLine("Word Document with default template initialized");
// Initialize the body with the new document
var body = new Openize.Words.Body(doc);
System.Console.WriteLine("Body of the Word Document initialized");
@openize-words-gists
openize-words-gists / Read-Word-Paragraphs.cs
Last active May 22, 2024 12:42
C# Read Word Document Paragraphs
// Prerequisite: Install <a href="https://www.nuget.org/packages/Openize.Words">Openize.Words</a>.
// Load the Word Document
var doc = new Openize.Words.Document($"WordParas.docx");
var body = new Openize.Words.Body(doc);
var num = 0;
System.Console.WriteLine("Paragraphs Plain Text");
// Traverse and display paragraphs with plain text
@openize-words-gists
openize-words-gists / Modify-Word-Paragraphs.cs
Created May 22, 2024 12:47
C# Modify Word Document Paragraphs
// Prerequisite: Install <a href="https://www.nuget.org/packages/Openize.Words">Openize.Words</a>.
// Load the Word Document
var doc = new Openize.Words.Document($"WordParas.docx");
var body = new Openize.Words.Body(doc);
foreach (var paragraph in body.Paragraphs)
{
foreach (var run in paragraph.Runs)
{
@openize-words-gists
openize-words-gists / Create-Word-Images.cs
Created May 22, 2024 12:51
C# Create Word Document Images
// Prerequisite: Install <a href="https://www.nuget.org/packages/Openize.Words">Openize.Words</a>.
// Initialize a new word document with the default template
var doc = new Openize.Words.Document();
// Initialize the body with the new document
var body = new Openize.Words.Body(doc);
// Load images from the specified directory
var imageFiles = System.IO.Directory.GetFiles(imageDirectory);
@openize-words-gists
openize-words-gists / Read-Word-Images.cs
Created May 22, 2024 12:55
C# Read Word Document Images
// Prerequisite: Install <a href="https://www.nuget.org/packages/Openize.Words">Openize.Words</a>.
// Load the Word Document
var doc = new Openize.Words.Document($"WordImgs.docx");
var body = new Openize.Words.Body(doc);
var num = 0;
// Traverse images and display metadata info
foreach (var img in body.Images)
{
@openize-words-gists
openize-words-gists / Modify-Word-Images.cs
Created May 22, 2024 12:59
C# Modify Word Document Images
// Prerequisite: Install <a href="https://www.nuget.org/packages/Openize.Words">Openize.Words</a>.
// Load the Word Document
var doc = new Openize.Words.Document($"WordImgs.docx");
var body = new Openize.Words.Body(doc);
foreach (var img in body.Images)
{
var skBitmap = SkiaSharp.SKBitmap.Decode(img.ImageData);
var skImage = SkiaSharp.SKImage.FromBitmap(skBitmap);
@openize-words-gists
openize-words-gists / Create-Word-Tables.cs
Created May 22, 2024 13:02
C# Create Word Document Tables
// Prerequisite: Install <a href="https://www.nuget.org/packages/Openize.Words">Openize.Words</a>.
// Initialize a new word document with the default template
var doc = new Openize.Words.Document();
System.Console.WriteLine("Word Document with default template initialized");
// Initialize the body with the new document
var body = new Openize.Words.Body(doc);
System.Console.WriteLine("Body of the Word Document initialized");
@openize-words-gists
openize-words-gists / Read-Word-Tables.cs
Created May 22, 2024 13:05
C# Read Word Document Tables
// Prerequisite: Install <a href="https://www.nuget.org/packages/Openize.Words">Openize.Words</a>.
// Load the Word Document
var doc = new Openize.Words.Document($"WordTables.docx");
var body = new Openize.Words.Body(doc);
var tables = body.Tables;
var tableNumber = 0;
var rowNumber = 0;
@openize-words-gists
openize-words-gists / Modify-Word-Tables.cs
Created May 22, 2024 13:07
C# Modify Words Document Tables
// Prerequisite: Install <a href="https://www.nuget.org/packages/FileFormat.Words">FileFormat.Words</a>.
// Load the Word Document
var doc = new FileFormat.Words.Document($"WordTables.docx");
var body = new FileFormat.Words.Body(doc);
var tables = body.Tables;
foreach (var table in tables)
{
@openize-words-gists
openize-words-gists / concurrent-processing-documents.cs
Created May 22, 2024 13:10
Multiple Word Documents Concurrent Updating in C#
// Concurrently updating three documents using <a href="https://www.nuget.org/packages/Openize.Words">Openize.Words</a>
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