Extract Shapes(or Drawings?) to Files

Hi, Guys


Is there any way to extract shapes(or drawings) like the attached picture to file
And get the position of these shapes?

Hi,

Thanks for your posting and using Aspose.Cells.

You can get the image of the shape using Shape.toImage() method. Also you can get the position of the Shape in terms of rows and columns using Shape.getUpperLeftRow(), Shape.getUpperLeftColumn(), Shape.getLowerRightRow() and Shape.getLowerRightColumn() methods.

Also, you get the absolute position of the shape as explained in this article.


Please see the following sample code that extracts all the shapes inside the worksheets and save them as images.

I have attached the source Excel file used in this code and the extracted images of the shapes for your reference.

Java

String filePath = “F:\Shak-Data-RW\Downloads\shapes.xlsx”;


Workbook workbook = new Workbook(filePath);


//Iterate all worksheets

for (int k = 0; k < workbook.getWorksheets().getCount(); k++)

{

Worksheet worksheet = workbook.getWorksheets().get(k);


//Save all shapes inside the sheet on disk

for (int i = 0; i < worksheet.getShapes().getCount(); i++)

{

Shape shape = worksheet.getShapes().get(i);


ImageOrPrintOptions options = new ImageOrPrintOptions();

options.setImageFormat(ImageFormat.getPng());


shape.toImage(filePath + “-” + worksheet.getName() + “-” + i + “.png”, options);

}//for

}//for