Set Font on Excel Sheet Using JExcel APIs.
Previous | Home | Next |
In this tutorial we will learn how can we set Font on Excel Sheet Using JExcel APIs.
For formatting the fonts used in the excel file we have to use the following class contained in the jxl.write package,
public class WritableFont extends jxl.write.biff.WritableFontRecord
This is a class which is instantiated when the user application wishes to specify the font for a particular cell.
WritableFont class have the several constructors which shows different behaviours on the basis of the parameters passed,
WritableFont(Font f)
It is the copy constructor which is available publicly.
WritableFont(WritableFont.FontName fnt)
This constructor creates a default font of the specified face and with default point size.
WritableFont(WritableFont.FontName fnt, int pointsize)
It constructs of font of the desired face and the size of the point specified by point size value.
WritableFont(WritableFont.FontName fnt, int pointsize, WritableFont.BoldStyle bldstyl)
It reates a font of the specified face, point size and with bold style.
WritableFont(WritableFont.FontName fnt, int pointsize, WritableFont.BoldStyle bldstyl, boolean italicisation)
This constructor creates a font of the specified face, point size, bold style and italicised option which is boolean ie true or false.
WritableFont(WritableFont.FontName fnt, int pointsize, WritableFont.BoldStyle bldstyl, boolean italicisation, UnderlineStyle undrlnstyl)
This constructor creates a font of the specified face, point size, bold style, italicisation and underline style for underlining the text.
WritableFont(WritableFont.FontName fnt, int pointsize, WritableFont.BoldStyle bldstyl, boolean italicisation, UnderlineStyle undrlnstyl, Colour c)
It creates a font of the specified face, point size, bold style, italicisation, underline style and colour.
WritableFont(WritableFont.FontName fnt, int pointsize, WritableFont.BoldStyle bldstyl, boolean italicisation, UnderlineStyle undrlnstyls, Colour c, ScriptStyle scptstyl)
This constructorc reates a font of the specified face, point size, bold style, italicisation, underline style, colour, and script style.
Then we passed the object of the WritableFont to the constructor of the WritableCellFormat class, and then we called the method setWrap(Boolean b) on the object of WritableCellFormat to enable cell formatting.
For setting the font in the excel sheet firstly we create the object of the WritableFont class and then pass that object on to the writablecell format class's constructor as a parameter, and then use that object of the WritableCellFormat class.
WritableFont wfobj2=new WritableFont(WritableFont.COURIER, 10, WritableFont.NO_BOLD);
WritableCellFormat wcf=new WritableCellFormat(wfobj2);
wcf.setAlignment(Alignment.LEFT);
wcf.setShrinkToFit(true);
wcf.setWrap(true);
Previous | Home | Next |