非基本形状中的数据

访问非基本形状的数据

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

非基本形状

在Aspose.Cells中,非基本形状被赋予类型AutoShapeType.NOT_PRIMITIVE。您可以使用Shape.getAutoShapeType()方法检查它们的类型。

使用Shape.getPaths()方法访问形状数据。它返回组成非基本形状的所有连接路径。这些路径是ShapePath的类型,它保存所有段落的列表,这些段落则包含每个段落中的点。

以下代码片段演示了使用Shape.getPaths()方法访问非基本形状的路径信息。

显示非基本形状的示例

todo:image_alt_text

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the resource directory
String dataDir = Utils.getSharedDataDir(NonPrimitiveShape.class) + "DrawingObjects/";
Workbook workbook = new Workbook(dataDir + "NonPrimitiveShape.xlsx");
Worksheet worksheet = workbook.getWorksheets().get(0);
// Accessing the user defined shape
Shape shape = worksheet.getShapes().get(0);
if (shape.getAutoShapeType() == AutoShapeType.NOT_PRIMITIVE) {
// Access Shape paths
ShapePathCollection shapePathCollection = shape.getPaths();
// Access information of individual shape path
ShapePath shapePath = shapePathCollection.get(0);
// Access shape segment path list
ShapeSegmentPathCollection shapeSegmentPathCollection = shapePath.getPathSegementList();
// Access individual segment path
ShapeSegmentPath shapeSegmentPath = shapeSegmentPathCollection.get(0);
ShapePathPointCollection segmentPoints = shapeSegmentPath.getPoints();
for (Object obj : segmentPoints) {
ShapePathPoint pathPoint = (ShapePathPoint) obj;
System.out.println("X: " + pathPoint.getX() + ", Y: " + pathPoint.getY());
}
}