Add different Formats

Add different Formats

Previous Home Next

 

In this section we will see how can we add different format to a spreadsheet using the JExcel API.

For adding different formats to the cell of  a sheet we have to use the following class,

public class WritableCellFormat extends jxl.write.biff.CellXFRecord

This class creates a user defined cell format, which can be reused across many cells. The constructors
of this class takes parameters, such as font details and the numerical date formats,which specify to
excel sheet how cells with this format should be displayed. Once a CellFormat has been added
to a Cell which has been added to a sheet, then that particular cell format will become immutable.
Any further attempts to call the various set functions on a WritableCellFormat after this time
will throw in a runtime exception. The constructor of the WritableCellFormat class have the following types,

WritableCellFormat()
It is the default constructor, which uses the default font and format.

WritableCellFormat(CellFormat format)
It is a public copy constructor which can be used for copying the formats between different sheets.

WritableCellFormat(jxl.biff.DisplayFormat format)
This constructor specifies a date/number format for Cells which use this format object

WritableCellFormat(WritableFont font)
This constructor  specifies the font for cells with this format

WritableCellFormat(WritableFont font, jxl.biff.DisplayFormat format)
This constructor specifies the font and date/number format for cells to use this format.
 The WritableCellFormat class have many different methods, some of which are as follows,

void setAlignment(Alignment align)
This method sets the horizontal alignment for the format

void setBackground(Colour clr)
It sets the background colour for the cell format
 
void setBackground(Colour c, Pattern p)
This method of WritableCellFormat sets the background colour and pattern for the cell format
 
void setBorder(Border b, BorderLineStyle ls)
It sets the specified border for the format.
 
void setBorder(Border b, BorderLineStyle ls, Colour c)
It sets the specified border for the format

void setIndentation(int i)
It sets the indentation of the cell text

void setLocked(boolean l)
This method sets whether or not this XF record locks the cell.

void setOrientation(Orientation o)
It sets the text orientation for thes format.
 
void setShrinkToFit(boolean s)
It sets the shrink to fit flag to true or false.
 
void setVerticalAlignment(VerticalAlignment va)
It sets the vertical alignment for the format
 
void setWrap(boolean w)
This method sets the wrap indicator for the format.
 


 

Previous Home Next