Bug 27153

Summary: Graphics resized when altering column widths
Product: POI Reporter: Tim Wilkins <timw>
Component: HSSFAssignee: POI Developers List <dev>
Status: RESOLVED WONTFIX    
Severity: normal CC: danny
Priority: P3    
Version: 2.0-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: The template XLS file that contains an image in the top left corner
The source code of the example
The compiled version of the test program

Description Tim Wilkins 2004-02-23 11:27:29 UTC
I have noticed a bug with POI 2.0 final release when dealing with excel sheets
that contain images and involving resizing columns on which the image spans.

I set the graphics properties to be independent of the cell's size and position.
Which causes the object to stay at its size even if I resize the column. This
does not work with HSSF. The graphic is being resized to column width but the
properties remain unchanged.

I have included a simple program example of this. This involves taking an excel
document as a template (ImageResizeExampleTemplate.xls) that contains an image
in the top left corner. The program takes this excel document template (it looks
for it on the root of your class path) and alters the 'A' column width to be
much wider than in the original. Finally the program creates a new excel
document (ImageResizeExampleOutput.xls) with the modified work book object.
Comment 1 Tim Wilkins 2004-02-23 11:30:25 UTC
Created attachment 10487 [details]
The template XLS file that contains an image in the top left corner
Comment 2 Tim Wilkins 2004-02-23 11:52:04 UTC
Created attachment 10488 [details]
The source code of the example
Comment 3 Tim Wilkins 2004-02-23 11:52:59 UTC
Created attachment 10489 [details]
The compiled version of the test program
Comment 4 Laurent Poublan 2008-03-20 02:34:11 UTC
This bug still exists in poi 3.0.2.
When I add an image and I resize one column or one row contained by its anchor, the image gets stretched.
The same problem occurs of course if I call sheet.autoSizeColumn(col);

The anchor type seems to be ignored. I can put whatever value to the anchor type, I get the same result.
anchor.setAnchorType(3); // 3=no resize/move
Comment 5 Yegor Kozlov 2008-03-20 12:08:10 UTC
Anchor type is not ignored. 

When you resize a column POI just updates the corresponding COLINFO record. No extra actions/calculations are performed. 
As opposed to it, on column resize Excel recomputes anchors of all pictures with anchor.type=2 so that they have the original dimensions.

I don't think POI should work this way and recompute anchors behind the scene. Probably we will add an explicit method HSSFSheet.updateAnchors() to do that. 
Implementing such a method right now is somewhat difficult because the HSSF drawing layer is mainly oriented on creating new drawings. The support for reading/modifying existing drawings is not very good. 

Yegor
Comment 6 Laurent Poublan 2008-03-21 01:26:20 UTC
Thank you for your quick answer.
However, I think something should be done for the following case:
if I create a picture on a patriarch and call resize() on it, the resizing is correct ONLY IF the rows/columns have the default height/width.
If the columns/rows width/height have been changed (before calling resize()), the resize does not set the image to its original size (proportions are modified).
I understand that changing cols/rows sizes after can alter images size, but I think HSSFPicture.resize() should always resize the image correctly.

Comment 7 Yegor Kozlov 2008-03-21 04:27:30 UTC
You are right about HSSFPicture.resize(). It doesn't take into account resized columns. I will see how it can be adjusted to work in all cases. 

Please keep in mind that HSSFPicture.resize() makes two important assumptions: 

 - default font is Arial 10pt. Usually it is so but if user goes to Excel options and selects a different font the result is unpredictable
 - display is 96 dpi. In most cases it is so but if you have a different setting you will see a stretched image even it looks fine at 96 dpi. 

Yegor
Comment 8 Laurent Poublan 2008-03-26 04:02:25 UTC
Will you reopen that bug or open a new bug for that?

Laurent
Comment 9 Yegor Kozlov 2008-03-27 09:34:32 UTC
Thanks for reminding. I opened a new bug.

Yegor