Rob Y
2008-11-06 21:27:34 UTC
I've been attempting to write code to fit an image (a variable,
client-specific logo file) into a rectangle within an HSSF spreadsheet.
That will involve scaling the x- and y-dimensions of the image to the
rectangle and then adjusting the rectangle so that both dimensions scale
identically to the new rectangle size.
The problem is controlling the rectangle size on a spreadsheet where it will
be layed out across multiple rows and columns, which are all part of the
normal spreadsheet grid and are sized accordingly.
I've got it kind of working in what seems to be the standard approach. I
scan rows and columns and create an anchor to describe a rectangular set of
cells. I use the anchor's dx,dy offsets to control how much the rectangle
spills into the last row and column. But it's proving really tricky to do
this with any accuracy, and my logos end up getting stretched and somewhat
distorted.
My question. Is this a shortcoming of the XLS file format? Are multi-cell
anchors the only way Excel has of storing image sizes in an XLS file, or is
there another mechanism that POI hasn't implemented yet?
Certainly, Excel lets you resize an image dynamically, and it's able to save
the exact size. What kind of 'magic' is it doing to get around the file
format limitations?
By the way, when I open my spreadsheet in OpenOffice 3.0, the size of the
images is all wrong. So if this anchor sizing is some strange feature of
XLS, apparently OOo doesn't handle it well.
client-specific logo file) into a rectangle within an HSSF spreadsheet.
That will involve scaling the x- and y-dimensions of the image to the
rectangle and then adjusting the rectangle so that both dimensions scale
identically to the new rectangle size.
The problem is controlling the rectangle size on a spreadsheet where it will
be layed out across multiple rows and columns, which are all part of the
normal spreadsheet grid and are sized accordingly.
I've got it kind of working in what seems to be the standard approach. I
scan rows and columns and create an anchor to describe a rectangular set of
cells. I use the anchor's dx,dy offsets to control how much the rectangle
spills into the last row and column. But it's proving really tricky to do
this with any accuracy, and my logos end up getting stretched and somewhat
distorted.
My question. Is this a shortcoming of the XLS file format? Are multi-cell
anchors the only way Excel has of storing image sizes in an XLS file, or is
there another mechanism that POI hasn't implemented yet?
Certainly, Excel lets you resize an image dynamically, and it's able to save
the exact size. What kind of 'magic' is it doing to get around the file
format limitations?
By the way, when I open my spreadsheet in OpenOffice 3.0, the size of the
images is all wrong. So if this anchor sizing is some strange feature of
XLS, apparently OOo doesn't handle it well.
--
View this message in context: http://www.nabble.com/images-and-anchors---controlling-image-size-tp20370056p20370056.html
Sent from the POI - User mailing list archive at Nabble.com.
View this message in context: http://www.nabble.com/images-and-anchors---controlling-image-size-tp20370056p20370056.html
Sent from the POI - User mailing list archive at Nabble.com.