Created
September 30, 2024 09:21
-
-
Save fileformat-words-gists/1d4616c967e597101145152a86d4a2e3 to your computer and use it in GitHub Desktop.
C# Create Modify 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 | |
var shapes = body.Shapes; | |
// Traverse through each shape, change the shape type to diamond and update document. | |
foreach (var shape in shapes) | |
{ | |
shape.Type = FileFormat.Words.IElements.ShapeType.Diamond; | |
doc.Update(shape); | |
} | |
// Save the modified Word Document | |
doc.Save($"shapes-modified.docx"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment