poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Yegor Kozlov <yegor.koz...@dinom.ru>
Subject Re: Question about HSSFSheet drawing patriarch
Date Wed, 06 Jul 2011 10:53:48 GMT
what happens when you re-create  a drawing patriarch is not
deterministic.  According to the documentation,
HSSFSheet.createDrawingPatriarch is supposed to wipe out any existing
drawings on the sheet. It *may* work for simple shapes, but evidently
fails for Pictures. I think it is because pictures are stores both in
workbook and sheet levels. Very schematically it can be described as
follows:

Workbook
[workbook-global drawing stuff]  // image blob lives here

Sheet1
[sheet1 drawings]   //  image properties (anchor, etc.) live here. The
shape refers to the blob in the workbook-global drawing

Sheet2
[sheet2 drawings]
....

HSSFSheet.createDrawingPatriarch invalidates everything on the sheet,
but does not clean its references in the workbook. This leads to the
*strange* behavior that you described.

I don't know how to bypass this limitation with the current drawing
support in HSSF. I will be happy to improve it to support modifying
existing drawings but it is not easy and will take quite a lot of time
and technical efforts.

My recommendation is not to recreate drawings.


Yegor

On Wed, Jul 6, 2011 at 11:05 AM, Martin Studer
<martin.studer@mirai-solutions.com> wrote:
> 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
>
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Mime
View raw message