SJ> Did you use "a" as the default character for any reason? Is that a standard SJ> assumption to make?
It's not documented. Just a guess :) Another variant is '0' but I can't tell for sure. It requires experiments. SJ> There seems to be a bug with HSSFSheet.getColumnWidth(). According to the SJ> javadocs, it should return the width of a column in units of 1/256 of a char SJ> width. This is ok if the column width has already been explicitly set with SJ> setColumnWidth(), but if not, it returns the same value as SJ> HSSFSheet.getDefaultColumnWidth(), which is measured in characters. So I'm SJ> getting the value 8 returned from getColumnWidth() for columns that haven't SJ> had their width changed. Is this a known issue? Looks so. Bug 25496 reports on it too. The fix is trivial but it can affect existing code. Any programs that assume getDefaultColumnWidth() returns 8 will be broken. I will look into it on the weekend. Yegor SJ> On 07/02/07, Yegor Kozlov <[EMAIL PROTECTED]> 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: [EMAIL PROTECTED] >> Mailing List: http://jakarta.apache.org/site/mail2.html#poi >> The Apache Jakarta Poi Project: http://jakarta.apache.org/poi/ >> >> --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] Mailing List: http://jakarta.apache.org/site/mail2.html#poi The Apache Jakarta Poi Project: http://jakarta.apache.org/poi/
