How to centralize image alignment in Excel using apache poi
HSSFPatriarch drawing = sheet.createDrawingPatriarch();
HSSFClientAnchor my_anchor = (HSSFClientAnchor) helper.createClientAnchor();
my_anchor.setAnchorType(HSSFClientAnchor.DONT_MOVE_AND_RESIZE);
my_anchor.setCol1(0);
// my_anchor.
my_anchor.setRow1(excelData.getRowNum());
strb.append(" ");
HSSFPicture my_picture = drawing.createPicture(my_anchor, my_picture_id);
/* Call resize method, which resizes the image */
my_picture.resize();
I am passing a sheet, helper as a parameter to my method.
with this code, the still image icon can be moved on the excel sheet. Also I want to set the vertical alignment of the icon in the cell as shown in the image below. Please suggest.
+3
source to share
1 answer
You can align the image with anchor, adjust the Dx1, Dy1, Dx2 and Dy2 values accordingly. Following is an example: -
ClientAnchor anchor = sheet.getWorkbook().getCreationHelper().createClientAnchor();
anchor.setDx1(0);
anchor.setDy1(0);
anchor.setDx2(0);
anchor.setDy2(0);
For a complete example, refer to the URL below: https://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/ss/examples/AddDimensionedImage.java
+1
source to share