Aspose.Cells on Java - Resize header picture relative to original size

Hi. Using Aspose.Cells for Java version 17.5.9.

I’d like to insert a user selected image as a header picture in our output. We can do that but the challenge is that we want to set a maximum height for the image and have it resize the width relative to that maximum height with respect to the scale of the original image. You can do this in Excel and the API hooks are seemingly there for Cells so I’m wondering if I’m just doing it wrong?

Here is the snippet I think is relative:

   // Creating a PageSetup object to get the page settings of the first worksheet of the workbook
    PageSetup pageSetup = workbook.getWorksheets().get(3).getPageSetup();

    // Setting the logo/picture in the central section of the page header
    pageSetup.setHeaderPicture(2, binaryData);

    // Setting the script for the logo/picture
    pageSetup.setHeader(2, "&G");

    //Pull the picture out
    Picture pic = pageSetup.getPicture(true, 2);
    //Set the aspect ratio to lock and keep it relative to the original

    //Set the height only

What we get as a result is a distorted width.

Thanks for the help.



Thanks for the sample code segment and details.

Please try our latest version/fix: Aspose.Cells for Java v17.8.4:

If you still find the issue with v17.8.4, kindly do provide us template file (if any), output file (after using the code segment) with header picture’s width wrong/distorted, image file (which you set it as header picture), you may zip all the files and attach it here. Moreover, please provide us a sample Excel file containing your desired header picture rightly placed, you may create your expected file in MS Excel manually, we will check it soon.


I’mattaching the zip file (98.7 KB)

Per your request I’ve included the following:

  1. Input workbook with no logo
  2. Output workbook with the logo on the sheet I want…but distorted. Note the width when inspected in Excel is 1.47" while the height is .67". My code is explicitly attempting to set it to .5 inches and my expectation would be that it would set the width to the same. I’ve done this with version 17.8.4.
  3. Source image…it’s 1.47" square
  4. Sample of of the workbook from #1 that I’ve manually added the image to the header in Excel. I then changed the height to .5" and the width scaled itself to match it automatically.

Thanks for the help.


Please set the width with the code as given below because we do not support automatically changing the width when LockAspectRatio is true.


pic.setWidthInch( pic.getWidthInch()*pic.getHeightScale() /100);