Data in Non-Primitive Shape

Accessing Data of Non-Primitive Shape

Sometimes, you need to access data from a shape that is not built-in. Built-in shapes are called primitive shapes; ones that aren’t are called non-primitive. For example, you can define your own shapes using different curve connected lines.

A Non-Primitive Shape

In Aspose.Cells, non-primitive shapes are assigned the type AutoShapeType.NotPrimitive. You can check their type using the Shape.AutoShapeType property.

Access the shape data using the Shape.Paths property. It returns all the connected paths that comprise the non-primitive shape. These paths are of the type ShapePath that holds a list of all the segments which in turn contain the points in each segment.

Shows an example of a non-primitive shape
todo:image_alt_text

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
Workbook workbook = new Workbook(dataDir + "NonPrimitiveShape.xlsx");
Worksheet worksheet = workbook.Worksheets[0];
// Accessing the user defined shape
Shape shape = worksheet.Shapes[0];
if (shape.AutoShapeType == AutoShapeType.NotPrimitive)
{
// Access shape's data
ShapePathCollection shapePathCollection = shape.Paths;
// Access information of indvidual path
foreach (ShapePath shapePath in shapePathCollection)
{
// Access path segment list
ShapeSegmentPathCollection pathSegments = shapePath.PathSegementList;
// Access individual path segment
foreach (ShapeSegmentPath pathSegment in pathSegments)
{
// Gets the points in path segment
ShapePathPointCollection segmentPoints = pathSegment.Points;
foreach (ShapePathPoint pathPoint in segmentPoints)
{
Console.WriteLine("X: " + pathPoint.X + ", Y: " + pathPoint.Y);
}
}
}
}