Back to Devexpress

ShapeCollection.Flatten() Method

officefileapi-devexpress-dot-spreadsheet-dot-shapecollection-d6226dd6.md

latest2.4 KB
Original Source

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.v25.2.Core.dll

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
IEnumerable<Shape> Flatten()
vb
Function Flatten As IEnumerable(Of Shape)

Returns

TypeDescription
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.

csharp
using System.Linq;
// ...

var pictures = worksheet.Shapes.Flatten()
    .Where(x => x.ShapeType == ShapeType.Picture)
    .Cast<Picture>();
vb
Imports System.Linq
' ...

Dim pictures = worksheet.Shapes.Flatten() _
    .Where(Function(x) x.ShapeType = ShapeType.Picture) _
    .Cast(Of Picture)()

See Also

ShapeCollection Interface

ShapeCollection Members

DevExpress.Spreadsheet Namespace