poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Steve Joynt" <steve.jo...@gmail.com>
Subject Re: Embedded images
Date Wed, 07 Feb 2007 22:42:24 GMT
Thanks, this is very helpful. A couple of things..

Did you use "a" as the default character for any reason? Is that a standard
assumption to make?

There seems to be a bug with HSSFSheet.getColumnWidth(). According to the
javadocs, it should return the width of a column in units of 1/256 of a char
width. This is ok if the column width has already been explicitly set with
setColumnWidth(), but if not, it returns the same value as
HSSFSheet.getDefaultColumnWidth(), which is measured in characters. So I'm
getting the value 8 returned from getColumnWidth() for columns that haven't
had their width changed. Is this a known issue?

Thanks,
Steve

On 07/02/07, Yegor Kozlov <yegor@dinom.ru> wrote:
>
>
> >>The problem is that the cell width and height don't seem to be measured
> in the same units.
> Exactly.
> Excel anchores objects against top-left and buttom-right cells. In
> addition it uses dx and dy for "fine positioning" relative to these
> cells. So to get the correct aspect ratio you need to know the number
> of cells and rows your image will occupy. Here it gets complicated :).
>
> The problem is that column width in Excel is expressed in units of 1/256th
> of a character width of the default font.
> Conversion from these weird 1/256th units to pixels is not trivial.
>
> The minimal steps to calculate width of a cell in pixels are as follows:
>
> - get default workbook font. HSSFWorkbook.getFontAt(0) should always
> return
> the default one.
> - get default cell width expressed in 1/256th units. See
> HSSFSheet.getColumnWidth
> - Assuming that the default character is "a" compute the width of a
> surrogate string using Java2D classes.
>
> image.width/cell.width is the number of columns to be used in the
>   anchor.
>
> I think this logic needs to be buried into POI API somehow. Probably
> it will be included in future.
>
> Regards,
> Yegor
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
> Mailing List:     http://jakarta.apache.org/site/mail2.html#poi
> The Apache Jakarta Poi Project:  http://jakarta.apache.org/poi/
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message