Thank you Yegor. It certainly helped, but as my default font is Helvetica Neue, it made the far too big.
I'll play around a little more. Kind Regards, Matt. Yegor Kozlov <[email protected]> 29/01/2009 05:37 PM Please respond to "POI Users List" <[email protected]> To POI Users List <[email protected]> cc Subject Re: Tools for calculating coordinates for HSSFClientAnchors You can use HSSFPicture.resize() to set the original size of an image. If topLeftX, topLeftY are set, HSSFPicture.resize() sets the new anchor relative to them. See the source code http://svn.apache.org/repos/asf/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFPicture.java Excel uses the coordinate system based on column-row grid, not on pixels. The conversion from column-row based coordinates into pixels is indeed tricky. The main difficulty is that Excel measures columns in units of 1/256th of a character width. That is, to set the original width of an image you need to calculate how many characters of the default font will occupy the image width. Current implementation of HSSFPicture.resize() is based on empirical constants found for Arial 10pt, the default font in most cases. Yegor > Hello All, > > Can someone please help me with a method or tool that allows me to convert > column width and row height settings into meaningful coordinate settings > for the HSSFClientAnchor class so I may insert an image into my > spreadsheet at full size? The documentation doesn't specify the units of > these coordinates, and they don't seem to correlate to pixels or any other > units denoted in the documentation. > > For example: > > The constructor call is: > HSSFClientAnchor imageAnchor = new HSSFClientAnchor( topLeftX, topLeftY, > bottomRightX, bottomRightY, startColumn, startRow, endColumn, endRow ); > > I have an image with width 308px and height 62px. > > I would like to calculate the appropriate settings for bottomRightX, and > bottomRight based in these pixel sizes (and the origin values in topLeftX > and topLeftY). > > After fiddling around with the values (and examining the errors thrown > when I exceeded the cell boundaries), I came up with: > 550, 0, 1023, 255 > > This seemed to be the closest I could get to the image size, but it still > isn't full size. This suggests that 62px translates roughly to 255 and > 308px translates to 473 (1023 - 550)? > > I'm sure I've missed something fundamental. > > Matt Robinson > --------------------------------------------------------------------------------------------------------------- > Disclaimer: > The information in this electronic mail message is confidential and may be legally privileged. > It is intended solely for the addressee. Access to this Internet electronic mail message by anyone else is > unauthorised. If you are not the intended recipient, any disclosure, copying, distribution or any action taken > or omitted to be taken in reliance on it is prohibited and may be unlawful. If you have received this e-mail > by mistake please call the sender immediately on 07 3853 5555 and erase the original message and any attachments. > The Company accepts no responsibility for any effects this email message or attachments has on the recipient > network or computer system. > --------------------------------------------------------------------------------------------------------------- > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] --------------------------------------------------------------------------------------------------------------- Disclaimer: The information in this electronic mail message is confidential and may be legally privileged. It is intended solely for the addressee. Access to this Internet electronic mail message by anyone else is unauthorised. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted to be taken in reliance on it is prohibited and may be unlawful. If you have received this e-mail by mistake please call the sender immediately on 07 3853 5555 and erase the original message and any attachments. The Company accepts no responsibility for any effects this email message or attachments has on the recipient network or computer system. ---------------------------------------------------------------------------------------------------------------
