Back to Devexpress

How to: Remove a Shape

officefileapi-120691-spreadsheet-document-api-examples-shapes-how-to-remove-a-shape.md

latest1.6 KB
Original Source

How to: Remove a Shape

  • Sep 19, 2023

This example illustrates how to remove a shape.

You can remove an item from the ShapeCollection using the ShapeCollection.RemoveAt method.

csharp
worksheet.Shapes.RemoveAt(3);
vb
worksheet.Shapes.RemoveAt(3)

If a target item is a Chart or Picture object, the ShapeCollection.RemoveAt method call removes this shape from two collections: ShapeCollection and ChartCollection or PictureCollection, respectively.

Call the Shape.Delete method to remove a Shape object directly. The code sample below shows how to remove all connectors from a worksheet.

csharp
foreach (Shape shape in worksheet.Shapes)
{
    if (shape.ShapeType == ShapeType.Connector)
        shape.Delete();
}
vb
For Each shape As Shape In worksheet.Shapes
    If shape.ShapeType = ShapeType.Connector Then shape.Delete()
Next