• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1396
  • Last Modified:

How to insert image in excel using jxl

Could you please give me the sample code to insert images in excel using jxl.
0
dattu070100
Asked:
dattu070100
1 Solution
 
david251Commented:
Have a look here:
http://jexcelapi.sourceforge.net/resources/faq/

I pasted some of the contents below.  HTH
-David251


import java.awt.image.BufferedImage;
      import java.io.ByteArrayOutputStream;
      import javax.imageio.ImageIO;
....
      private static final double CELL_DEFAULT_HEIGHT = 17;
      private static final double CELL_DEFAULT_WIDTH = 64;
....
      File imageFile = new File(GIF_OR_JPG_IMAGE_FILE);
      BufferedImage input = ImageIO.read(imageFile);
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      ImageIO.write(input, "PNG", baos);
      sheet.addImage(new WritableImage(1,1,input.getWidth() / CELL_DEFAULT_WIDTH,
            input.getHeight() / CELL_DEFAULT_HEIGHT,baos.toByteArray()));

0

Featured Post

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

Tackle projects and never again get stuck behind a technical roadblock.
Join Now