Last active
September 30, 2024 09:22
-
-
Save fileformat-words-gists/1b2f4fec37167dd4442e31788020876e to your computer and use it in GitHub Desktop.
C# Read Shapes in Word Documents
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Prerequisite: Install <a href="https://www.nuget.org/packages/FileFormat.Words">FileFormat.Words</a>. | |
// Load the Word Document. | |
var doc = new FileFormat.Words.Document($"shapes.docx"); | |
// Initialize the body with the loaded document. | |
var body = new FileFormat.Words.Body(doc); | |
// Load all shapes with the document | |
var shapes = body.Shapes; | |
// Initialize the shape counter | |
var shapeNumber = 0; | |
// Traverse through each shape and display its properties | |
foreach (var shape in shapes) | |
{ | |
shapeNumber++; | |
System.Console.WriteLine($"Shape Number : {shapeNumber}"); | |
System.Console.WriteLine($"...Shape Type : {shape.Type}"); | |
System.Console.WriteLine($"...X Position : {shape.X}"); | |
System.Console.WriteLine($"...Y Position : {shape.Y}"); | |
System.Console.WriteLine($"...Width : {shape.Width}"); | |
System.Console.WriteLine($"...Height : {shape.Height}"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment