Extract images from excel sheets in java

Hi,


How to extract images from excel sheets in java?

Hi,

Thanks for your posting and using Aspose.Cells for Java.

You can extract all the images present in a worksheet using Worksheet.getPictures() method. It will returns the collection of all the pictures, which you can then save one by one on your disk.

Please see the sample code below. It extracts all the images from the first worksheet of the source file.

I have attached the source xlsx file, output images and screenshots for your reference.

Java


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


Workbook workbook = new Workbook(filePath);


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


PictureCollection pics = worksheet.getPictures();


//Write all the extracted images on disk

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

{

Picture pic = pics.get(i);


byte[] picBytes = pic.getData();

String picExtension = pic.getImageFormat().getName();


FileOutputStream fout = new FileOutputStream(“image_”+ i + “.” + picExtension);

fout.write(picBytes);

fout.close();


}//for

Screenshot: