Date Formatting on Cells.
Previous | Home | Next |
In this tutorial we will see how can we apply formatting on the Date cells of an spreadsheet using the JExcel API.
For formatting the dates in a spreadsheet we have to use the jxl.write.DateFormats class. This class have the following structure,
public final class DateFormats extends java.lang.Object
It is a static class that contains Excels predefined Date formats.
WritableCellFormat wcfdate=new WritableCellFormat(DateFormats.FORMAT2);
wcfdate.setAlignment(Alignment.LEFT);
wcfdate.setWrap(true);
DateTime dtobj=new DateTime(4, 1, new Date(), wcfdate);
sheet.addCell(dtobj);
The above procedure is used for formatting the date cell of a spreadsheet. Firstly we create an object of writable cell format in which we set the DateFormats format and do some other additional formatting, then lastly we created an object of DateTime class and pass the various values to the writable cell class constructor and then finally add the date field to the sheet.
Previous | Home | Next |