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

On Thu, Sep 11, 2008 at 5:34 PM, Nick Burch <[EMAIL PROTECTED]> wrote:
> On Thu, 11 Sep 2008, Thorsten Bux wrote:
>>
>> does anybody know how to set the width and height of an excel cell to a
>> specific size in pixel?
>
> I think the two methods you'll want are:
> 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)
>
>> also 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)
>
> Nick
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>



-- 
Cordialement,
Pierre Lavignotte
Ingénieur Conception & Développement
http://pierre.lavignotte.googlepages.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to