非原始の形のデータ
非原始の形のデータへのアクセス
時々、ビルトインでない形状からデータにアクセスする必要があります。ビルトインの形状は原始形状と呼ばれ、そうでないものは非原始形状と呼ばれます。例えば、異なる曲線接続線を使用して独自の形状を定義することができます。
非原始の形状
Aspose.Cellsでは、非プリミティブ形状にはタイプAutoShapeType.NOT_PRIMITIVEが割り当てられます。Shape.getAutoShapeType()メソッドを使用してタイプを確認できます。
Shape.getPaths()メソッドを使用して形状データにアクセスします。非プリミティブ形状を構成するすべての接続パスを返します。これらのパスは、各セグメント内の点を含むすべてのセグメントを保持するShapePathのタイプである。
次のコードスニペットは、非プリミティブ形状のパス情報にアクセスするShape.getPaths()メソッドの使用例を示しています。
非プリミティブ形状の例を示します
// 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()); | |
} | |
} |