Dati in Forma Non Primitiva con C++
Accesso ai Dati di Forma Non-Primitiva
A volte, è necessario accedere ai dati da una forma non incorporata. Le forme incorporate sono chiamate forme primitive; quelle che non lo sono vengono chiamate non primitive. Ad esempio, è possibile definire le proprie forme utilizzando diverse linee collegate da curve.
Una Forma Non-Primitiva
In Aspose.Cells, alle forme non primitive viene assegnato il tipo AutoShapeType.NotPrimitive. È possibile controllare il loro tipo utilizzando la proprietà Shape.AutoShapeType.
Accedere ai dati della forma utilizzando la proprietà Shape.GetPaths(). Restituisce tutti i percorsi collegati che compongono la forma non primitiva. Questi percorsi sono del tipo ShapePath che contiene un elenco di tutti i segmenti che a loro volta contengono i punti in ciascun segmento.
Mostra un esempio di una forma non primitiva |
---|
![]() |
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
using namespace Aspose::Cells::Drawing;
int main()
{
Aspose::Cells::Startup();
// Source directory path
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
// Load the workbook
Workbook workbook(srcDir + u"NonPrimitiveShape.xlsx");
// Access the first worksheet
Worksheet worksheet = workbook.GetWorksheets().Get(0);
// Accessing the user defined shape
Shape shape = worksheet.GetShapes().Get(0);
if (shape.GetAutoShapeType() == AutoShapeType::NotPrimitive)
{
// Access shape's data
ShapePathCollection shapePathCollection = shape.GetPaths();
// Access information of individual path
for (int i = 0; i < shapePathCollection.GetCount(); ++i)
{
ShapePath shapePath = shapePathCollection.Get(i);
// Access path segment list
ShapeSegmentPathCollection pathSegments = shapePath.GetPathSegementList();
// Access individual path segment
for (int j = 0; j < pathSegments.GetCount(); ++j)
{
ShapeSegmentPath pathSegment = pathSegments.Get(j);
// Gets the points in path segment
ShapePathPointCollection segmentPoints = pathSegment.GetPoints();
for (int k = 0; k < segmentPoints.GetCount(); ++k)
{
ShapePathPoint pathPoint = segmentPoints.Get(k);
std::cout << "X: " << pathPoint.GetX() << ", Y: " << pathPoint.GetY() << std::endl;
}
}
}
}
Aspose::Cells::Cleanup();
return 0;
}