Skip to content

Instantly share code, notes, and snippets.

@fileformat-words-gists
Created September 30, 2024 09:21
Show Gist options
  • Save fileformat-words-gists/1d4616c967e597101145152a86d4a2e3 to your computer and use it in GitHub Desktop.
Save fileformat-words-gists/1d4616c967e597101145152a86d4a2e3 to your computer and use it in GitHub Desktop.
C# Create Modify Shapes in Word Documents
// 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