We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Image height stretching


I am currently working on a reporting application and I am having a problem with images stretching on Excel Worksheets. I am preforming an XSL transform on the Worksheets and then I add the images after the transform is completed. The transform modifies the height and width of the specified cells.

It appears that when I add the images they are stretching to the columns height and width even if I set the image height and width.

Below is a snip it of code of how I set the images height and width.

asposeWorksheet.getPictures().get( imageIndex ).setWidthScale( 100 );
asposeWorksheet.getPictures().get( imageIndex ).setHeightScale( 100 );

When I view the properties of the image in the final Excel file the image is set to 176% height and 101% width.

Any help with this issue would be greatly appreciated!

I am using aspose-cells-7.4.1.jar



Aspose.Cells works the same way as MS Excel does, so it might possible that when you simply insert images from your source, they are stretched a bit automatically due to MS Excel behavior. Please do try your process in MS Excel manually and check if you find the similar results as per Aspose.Cells provides. If you find different results, kindly do create a sample console application, zip it and post it here to reproduce the issue on our end. We will check it soon. Also provide some screen shots when you manually perform the steps in MS Excel to better understand the difference.

By the way, for: “It appears that when I add the images they are stretching to the columns height and width even if I set the image height and width”, could you also try to some options (e.g set placement to free floating, etc.) if it makes any difference.
//Add a picture to the C4 cell only.
int index = worksheet.Pictures.Add(3, 2, 4, 3, “e:\test\school.jpg”);
//Get the picture object
Aspose.Cells.Drawing.Picture pic = worksheet.Pictures[index];
//Set the placement type
pic.Placement = PlacementType.FreeFloating;

Thank you.

Hi Amjad Sahi,

I am sorry for the dramatic delay in my response to your post.

I have attached an example java class along with an xsl and xml document that is used in the Excel transform process.

I tried the suggestions you made and it made no difference in the image sizing unfortunately. As you will see in the example project.

Thank you for help,


Thanks for the sample SpreadsheetML file, image and Java program.

After an initial test, I can notice the issue as you pointed out, the issue is with image’s height which is always stretched a bit when rendering to MS Excel.

Sample code:

//Create Aspose Workbook
Workbook asposeWorkbook = new Workbook( ImageBug.class.getResourceAsStream( “Workbook1.xml” ) );

WorksheetCollection worksheets = asposeWorkbook.getWorksheets();
//Get the first worksheet in the workbook
Worksheet sheet = worksheets.get( 0 );

//Add the image
int picIndex = sheet.getPictures().add( 0, 0, “f:\files\logo.jpg” );

System.out.println(sheet.getPictures().get( picIndex ).getWidthCM()); // 3.39 OK
System.out.println(sheet.getPictures().get( picIndex ).getHeightCM());// 3.39 OK

//tried but in vain.
sheet.getPictures().get( picIndex ).setHeightCM(sheet.getPictures().get( picIndex ).getHeightCM());

sheet.getPictures().get( picIndex ).setPlacement( PlacementType.FREE_FLOATING );

// does not work either.
sheet.getPictures().get( picIndex ).setWidthScale( 100 );
sheet.getPictures().get( picIndex ).setHeightScale( 100 );

// sheet.getPictures().get( picIndex ).move( 1, 1 );

//Save the Excel file
asposeWorkbook.save( “TestExcel.xlsx” );

I have logged a ticket with an id “CELLSJAVA-40463” for your issue. We will look into your issue soon.

Once we have any update on it, we will let you know here.

Thank you.

The issues you have found earlier (filed as CELLSJAVA-40463) have been fixed in this update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.


Thank you for this update. It has solved the image stretching bug.



Thanks for your posting and using Aspose.Cells.

We are
pleased to know that your issue is resolved. If you face any other
issue, please feel free to post on our forums, we will be happy to help
you more.