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

Free Support Forum - aspose.com

Align an image in a cell to center it both vertically and horizontally in Java

Hi Team,

I’ve a scenario in which the image in a particular cell to be aligned center (both vertically and horizontally).

Existing Scenario :
image.png (10.5 KB)

Required Scenario :
image.png (8.9 KB)

Could you please help me with some sample java code to achieve this.

Thanks in advance,
Sanjeev

@sanjeevkumarambti,

Thanks for the screenshots.

Please refer to this help topic:Managing Pictures. Picture/ Shape class offers setUpperDeltaX, setUpperDeltaY, setLeft and setTop methods and other attributes to accomplish the task. See the following code segment for your reference:
e.g
Sample code:

// Positioning the picture proportionally to row height and column width
picture.setUpperDeltaX(200);
picture.setUpperDeltaY(200);

// Absolute positioning of the picture in unit of pixels
picture.setLeft(60);
picture.setTop(10);

By the way, you may create your sample Excel file manually using MS Excel with your picture on desired position and its size, now load it using Aspose.Cells and check different attributes so you may set these via code.