非基本形状中的数据

访问非基本形状的数据

有时,您需要访问非内置形状的形状的数据。内置形状称为基本形状;而不是内置形状的称为非基本形状。例如,您可以使用不同的曲线连接线定义自己的形状。

非基本形状

在Aspose.Cells中,非原始形状分配的类型为 AutoShapeType.NotPrimitive。您可以使用 Shape.AutoShapeType 属性检查它们的类型。

使用 Shape.Paths 属性访问形状数据。它返回组成非原始形状的所有连接路径。这些路径的类型为 ShapePath,包含了所有段的列表,而每个段又包含了每个段中的点。

显示了非原始形状的示例
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);
}
}
}
}