Hi,
I have a ods document which contains images and chart. I want to remove the images in the document. Tried using below code that removed all the Charts and images. But i want to remove only the images. How can i do that? Attached the input file.
My code is,
com.aspose.cells.Worksheet sheet = wb.getSheet(“Sheet1”);
com.aspose.cells.Shapes shapes = sheet.getShapes();
int size = shapes.size();
int index = 0;
while(size > 0)
{
boolean removed = shapes.removeShape(index);
size–;
}
Regards,
Santhosh
Hi,
I think, there is no difference between picture and image. Kindly define what do you mean, when you only want to remove only images and not pictures.
Hi,
Sorry, i mean images and charts. I want to remove only the images not charts. How can i do that. Can you reply this immediately?
Regards,
Santhosh
Hi,
Just check, if shape is of type picture, if yes, then remove it otherwise don’t remove. I will provide you code example asap.
Hi,
Please see the code below. I used your input.ods file. Please see the generated output ods file attached by me.
Java
String path = “F:\Shak-Data-RW\Downloads\Files\input.ods”;
Workbook workbook = new Workbook();
workbook.open(path);
Worksheet worksheet = workbook.getWorksheets().getSheet(0);
for(int j=worksheet.getShapes().size()-1; j>=0; j–)
{
com.aspose.cells.Shape shp = worksheet.getShapes().get(j);
if (shp instanceof com.aspose.cells.Picture)
worksheet.getShapes().removeShape(j);
}
workbook.save(path + “.out.java.ods”, FileFormatType.ODS);
Thank you for your help. It’s working fine.