Maybe it is stupid question, but i can not find solution How can i set row height depending on image height? Here is part of my code:
int pictureIdx = workBook.addPicture(bytes, Workbook.PICTURE_TYPE_JPEG);
CreationHelper helper = workBook.getCreationHelper();
Drawing drawing = sheet.createDrawingPatriarch();
ClientAnchor anchor = helper.createClientAnchor();
anchor.setCol1(0);
anchor.setRow1(i);
anchor.setAnchorType(ClientAnchor.MOVE_AND_RESIZE);
HSSFPicture pict = (HSSFPicture) drawing.createPicture(anchor, pictureIdx);
Dimension size = pict.getImageDimension();
double scaledWidth = size.getWidth();
double procentage = (1070.0d * 100d) / scaledWidth;
double autosize = procentage / 100.0d;
pict.resize(autosize);
short h = (short) (pict.getImageDimension().getWidth());
row.setHeight(h);
in Excel my image height is much bigger than row height
Doubt you would still need this after one year but for what its worth, you are assigning the pictures width as row height.
short h = (short) (pict.getImageDimension().getWidth());
Also setHeight uses twip as unit, which is 1/20 of point. So you still need to multiply your h value by a factor of more than 20 to get into pixel range.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With