Set Border of Cell’s on Excel Sheet Using JExcel APIs.

Set Border of Cell’s on Excel Sheet Using JExcel APIs.

Previous Home Next

 

In this part of the tutorial we will learn how can we set the Border of Cell on Excel Sheet Using JExcel APIs.

For setting the border of an excel sheet's cell, we have to import the following classes,

import jxl.format.Border;
import jxl.format.BorderLineStyle;

As well as, we have also to import jxl.write.WritableFont class for setting the border of the cell.
 The following code snippet will show how can we set the border of a cell in a excel worksheet,

 WritableFont wfobj=new WritableFont(WritableFont.TIMES, 10, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE,Colour.BLUE);
        WritableCellFormat cfobj=new WritableCellFormat(wfobj);
        cfobj.setBackground(Colour.GREY_25_PERCENT);
        cfobj.setAlignment(Alignment.LEFT);
        cfobj.setOrientation(Orientation.HORIZONTAL);
        cfobj.setBorder(Border.RIGHT, BorderLineStyle.MEDIUM_DASH_DOT,Colour.BLACK);
       
       
        cfobj.setShrinkToFit(true);
        cfobj.setWrap(true);

In the above code we have created a WritableCellFormat object and then on that object we have set the border by using the setBorder() method. This method have following two forms viz,

void setBorder(Border b, BorderLineStyle bls)
 It sets the specified border for this format

 void setBorder(Border b, BorderLineStyle bls, Colour clr)
  Sets the specified border for this format
       


 

Previous Home Next