I hope my belated answer is of help

HSSFPicture.resize() as well as XSSFPicture.resize() indeed work only for the default font which is Arial 10pt for .xls and Calibri 11pt for .xlsx.

Excel uses a funny coordinate system to position graphic objects. X and Y axes are measured not in pixels but in units proportional to a character width of the default font. To properly position and size an image POI needs to translate the actual dimensions measured in pixels to columns and rows. This is the key of the problem. At the moment POI performs this translation using hardcoded constants obtained empirically for Arial 10pt and Calibri 11pt. It works OK in most cases and also explains why HSSFPicture.resize() is 'off' if the default font is changed.

Unfortunately it can not be easily fixed. To measure a custom font POI needs to load it (i.e. the font must be physically available) and get the font metrics using java.awt.* utilities. It will make the result machine dependent and impossible to test.

I'm going to update javadocs on HSSFPicture.resize() and close Bug 48415 as 
'wontfix'

Yegor

Dear all,

As my test result, this function only works when the default font size of
workbook not changed. If I modified its size (For example, from 12 to 22)
and then call this function to insert an image, it stretchs horizontally.

Image 1 (Default font size set to 12):
http://old.nabble.com/file/p26738706/1.jpg
Image 2 (Default font size set to 22):
http://old.nabble.com/file/p26738706/2.jpg
I've checked the source code of HSSFPicture.java, function resize() calls
another function getPixelWidth() to calculate the column width in pixels,
but the later function only works correctly when the default font size of
workbook not changed.

Can somebody give me some suggestions to correct this problem? Thanks.

George


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to