You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Martin Studer <ma...@mirai-solutions.com> on 2011/07/06 09:05:25 UTC
Question about HSSFSheet drawing patriarch
Dear POI Users/Developers,
I've got a question on the HSSFSheet drawing patriarch. In the documentation
of HSSFSheet.createDrawingPatriarch it says: "Creates the top-level drawing
patriarch. This will have the effect of removing any existing drawings on
this sheet. This may then be used to add graphics or charts."
So given that I have a workbook that already contains images, I would expect
any existing images to be removed. However, the effect that I get when
calling HSSFSheet.createDrawingPatriarch (and later Drawing.createPicture)
is that the previous images will just be replaced with the new image - they
are not removed. Also, the image does not appear at the new location
(anchor) that I've set.
Here is an excerpt of the code:
InputStream is = new FileInputStream(imageFile);
byte[] bytes = IOUtils.toByteArray(is);
int imageIndex = workbook.addPicture(bytes, imageType);
is.close();
Drawing drawing = sheet.createDrawingPatriarch();
CreationHelper helper = workbook.getCreationHelper();
ClientAnchor anchor = helper.createClientAnchor();
anchor.setRow1(topLeft.getRow());
anchor.setCol1(topLeft.getCol());
anchor.setRow2(bottomRight.getRow() + 1);
anchor.setCol2(bottomRight.getCol() + 1);
anchor.setAnchorType(ClientAnchor.DONT_MOVE_AND_RESIZE);
Picture picture = drawing.createPicture(anchor, imageIndex);
I guess I must be doing something wrong? I'm using POI 3.8-beta3.
Any help is very much appreciated.
Thank you and best regards,
Martin