Image stretching out the cell borders - How to resize image to fit in cell?

Hello Team,

We’re developing excel report using Aspose Java Cells where we want to add multiple images of different sizes. What I’ve observed is, the images of horizontal sizes (image width > image height) gets automatically resized but images in vertical sizes (image height > image width) stretches out of excel cell as shown below. Could you please let us how can we fix this?

Also, is it possible to align images at the center of the cell?



Thanks for providing us some details and screen shot.

Please try our our latest version/fix: Aspose.Cells for Java v8.6.3 (if you are not already using it)

If you still find the issue (regarding stretching images), could you give us sample JAVA code (runnable) with your template and image files to show the issue, we will check it soon.

Also, regarding re-sizing images to fit into the cell, you may refer to the following code segment for your requirements:
Sample code:

//Adding the chart image from previous step to the A1 cell
int index = worksheet.getPictures().add(0, 0, “f:/files/image1.emf”);
Picture picture = sheet.getPictures().get(index);

//Retrieving the inserted image size
int height = picture.getHeight();
int width = picture.getWidth();

//Expanding the A1 cells according to the picture size
sheet.getCells().setColumnWidthPixel(0, width);
sheet.getCells().setRowHeightPixel(0, height);

//Note: you may implement the other way also, i.e., get the column width and row height where to insert the image, re-size the image’s width and height accordingly.

Thank you.