poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Yegor Kozlov <yegor.koz...@dinom.ru>
Subject Re: Images in excel - performance issue
Date Fri, 02 Nov 2012 13:15:18 GMT
are you sure the bottle neck is in POI ? Can it be read-write in ImageIO ?

On Fri, Nov 2, 2012 at 5:01 PM, Abhi <abhilash.g@gmail.com> wrote:
> Hi,We are implementing export to excel functionality using POI 3.8. The
> requirement is to have images in one of the cell. We are using image in
> 120X120 pixel size and inserting into excel using POI code. For 50 rows with
> image in one cell, it is approximately taking 2 hours.
>
> Is there any way to reduce the size? If I run the same code without images
> it works very fast.
> Here is the sample code:
>
>
>     private void createImageCell(Workbook wb,Sheet sheet,CreationHelper
> createHelper,String imagePath,int rowNum, int colNum,Drawing drawing)    {
>                 try             {
>                         int pictureIdx  = compressImage(wb,imagePath,false);
> if(pictureIdx>=0)                       {
>                             //add a picture shape                           ClientAnchor
anchor =
> createHelper.createClientAnchor();                          //set top-left corner of
the
> picture,
>                             //subsequent call of Picture#resize() will operate relative
to it
> anchor.setCol1(colNum);
>                             //anchor.setCol2(colNum+1);
>                             anchor.setRow1(rowNum);
>                             //anchor.setRow2(rowNum+2);
>                             anchor.setAnchorType(ClientAnchor.DONT_MOVE_AND_RESIZE);
>                             Picture pict = drawing.createPicture(anchor, pictureIdx);
>                             pict.resize();                      }               }
>                 catch(Exception exe)            {                       message +=" 
"+exe.getMessage();
> System.out.println("  "+exe);                   exe.printStackTrace();
>                 }    }
>
>     private int compressImage(Workbook wb,String imagePath,boolean
> compressImageFlag)    {
>         byte[] imageBytes = null;
>         InputStream is = null;
>         int pictureIdx = -1;
>         Integer picIndex = null;
>         try             {
>                 picIndex = picIndexMap.get(imagePath);
>                 if(picIndex == null)                    {
>                         ByteArrayOutputStream byteArrayOutStream = new
> ByteArrayOutputStream();
>                         BufferedImage originalImage = ImageIO.read(new URL(imagePath));
>                         ImageIO.write(originalImage, "jpg", byteArrayOutStream);
>                         imageBytes = byteArrayOutStream.toByteArray();
>                         pictureIdx = wb.addPicture(imageBytes, Workbook.PICTURE_TYPE_JPEG);
>                         picIndex = new Integer(pictureIdx);
>                         picIndexMap.put(imagePath, picIndex);                   }   
   }
>         catch (IOException e)           {
>                  message += "Compress image IOUtils "+e.getMessage();
>                  picIndex = new Integer(pictureIdx);            }
>         finally         {         if(is != null)          {
> IOUtils.closeQuietly(is);         }     }
>                 if(picIndex != null)            {               return picIndex.intValue();
    }
>         else            {               return -1;      }
>    }
>
>
>
> --
> View this message in context: http://apache-poi.1045710.n5.nabble.com/Images-in-excel-performance-issue-tp5711368.html
> Sent from the POI - Dev mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Mime
View raw message