Skip to main content
Row

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

ShapeCollection.Flatten() Method

Converts a shape collection into a flattened collection that contains all drawing objects in a worksheet, including items of shape groups.

Namespace: DevExpress.Spreadsheet

Assembly: DevExpress.Spreadsheet.v24.2.Core.dll

NuGet Package: DevExpress.Spreadsheet.Core

#Declaration

IEnumerable<Shape> Flatten()

#Returns

Type Description
IEnumerable<Shape>

A flattened collection of drawing objects in a worksheet.

#Remarks

The ShapeCollection contains the standalone drawing objects and shape groups. It stores each group as a single shape and does not include the group’s items. Use the group’s Shape.GetChildren method to iterate through its elements.

The Flatten method recursively iterates through the ShapeCollection and its groups to retrieve all drawing object contained in a worksheet. If you need to obtain drawing objects of a specific type, filter the resulting collection by ShapeType.

For instance, the following code snippet shows how to collect all pictures from a worksheet.

using System.Linq;
// ...

var pictures = worksheet.Shapes.Flatten()
    .Where(x => x.ShapeType == ShapeType.Picture)
    .Cast<Picture>();
See Also