thanks for your reply.
I tried something like this too.
The problem with this algorithm is, that a picture in the next row and same column may be smaller than the width of the column. If that is the case it should keep its size.
Datum: Thu, 11 Sep 2008 17:38:48 +0200
Betreff: Re: setting excel cells to a specific width and height in pixel
Hi,
I've found this piece of code in my test project.
I can't remember why some code is commented out, but I know that 1023
and 255 values mean that you fill the cell with the image (ie 100%).
private void drawImage(short col, int row, InputStream in,
HSSFWorkbook workbook,
HSSFPatriarch patriarch) throws IOException, NullPointerException {
if (in == null) {
throw new NullPointerException("Fichier image null");
}
//Conversion de l'image au format png(format de JEXCEL).
ByteArrayOutputStream out = new ByteArrayOutputStream();
BufferedImage input = ImageIO.read(in);
ImageIO.write(input, "PNG", out);
double imgWidth = input.getWidth();
double imgHeight = input.getHeight();
// double ratio = imgWidth / imgHeight;
// double ratioXl = 1; //sizeColum/sizeRow;
// double SIZE_LIMIT_WIDTH = 0.9;
// double SIZE_LIMIT_HEIGHT = SIZE_LIMIT_WIDTH * ratioXl;
//
// if (imgHeight <= imgWidth) {
// imgWidth = SIZE_LIMIT_WIDTH;
// imgHeight = (SIZE_LIMIT_HEIGHT / ratio);
// } else {
// imgHeight = SIZE_LIMIT_HEIGHT;
// imgWidth = SIZE_LIMIT_WIDTH * ratio;
// }
HSSFClientAnchor anchor;
anchor = new HSSFClientAnchor(0, 0, 1023, 255,
col, row, col, row);
anchor.setAnchorType(2);
int pictureIndex = workbook.addPicture(out.toByteArray(),
HSSFWorkbook.PICTURE_TYPE_PNG);
patriarch.createPicture(anchor, pictureIndex);
}
Hope it helps,
Pierre
Post by Nick BurchPost by Thorsten Buxdoes anybody know how to set the width and height of an excel cell to a
specific size in pixel?
http://poi.apache.org/apidocs/org/apache/poi/hssf/usermodel/HSSFRow.html#setHeightInPoints(float)
http://poi.apache.org/apidocs/org/apache/poi/hssf/usermodel/HSSFSheet.html#setColumnWidth(short,%20short)
Post by Nick BurchPost by Thorsten Buxalso i would like to know how to set a cell to the max. possible height and width.
Try giving those two methods really large values? (Not sure, haven't
tried)
Post by Nick BurchNick
---------------------------------------------------------------------
--
Cordialement,
Pierre Lavignotte
Ingénieur Conception & Développement
http://pierre.lavignotte.googlepages.com
---------------------------------------------------------------------