How To Use Images on Excel Sheet Using JExcel APIs.

How To Use Images on Excel Sheet Using JExcel APIs.

Previous Home Next

 

Now we will learn how to Use Images on Excel Sheet Using JExcel APIs.

For adding the images to your worksheet, you  have to use the jxl.write.WritableImage class, whose syntax  in general is given as,

public class WritableImage extends jxl.biff.drawing.Drawing

This class allows an image to be created, or an existing image to be manipulated  The values of the co-ordinates and dimensions are given in cells, so that if for example the width or height of a cell which the image spans is altered, the image will be having a corresponding distortion. The WritableImage have the following constructors that are used,

WritableImage(double x, double y, double width, double height, byte[] imageData)
This constructor creates an image of specified width and height and of specified image data.

WritableImage(double x, double y, double width, double height, File image)
This constructor constructs an image of specified width and height from the file.         

WritableImage(jxl.biff.drawing.DrawingGroupObject d, jxl.biff.drawing.DrawingGroup dg)
This constructor is used when sheets are being copied.
 The following code snippet will show you how to add an image to your current worksheet,

WritableImage mgobj=new WritableImage(5, 2, 1, 1, new File("F:/JAVA PROJECTS/Jexcel/Winter.png"));
sheet.addImage(imgobj);

In the above code we have created an WritableImage object and in the constructor of the WritableImage we passed the column and row for the height and width and open the image contained in a certain file at the certain location. After that we have called the addImage() method on the sheet and passed the WritableImage object to it as an argument.
 


 

Previous Home Next