assing Date into cells
In this program, we are going to pass date into the cells in excel sheet using java .You have create any number of cells and rows and also you can pass different data types into cells.
The package we need to import is :
java.io.*,
org.apache.poi.hssf.usermodel.HSSFSheet,
org.apache.poi.hssf.usermodel.HSSFCell,
org.apache.poi.hssf.usermodel.HSSFRow,
org.apache.poi.hssf.usermodel.HSSFCellStyle,
org.apache.poi.hssf.usermodel.HSSFFormat,
org.apache.poi.hssf.usermodel. HSSFWorkbook.
org.apache.poi.hssf.usermodel.HSSFCellStyle class is used to create an
object of HSSFCellStyle. By using this style object we set the format of the
cell data values. For this we use
setDataFormate(HSSFDataFormat.getBuiltinFormat("m/d/yy h:mm")).
createCellStyle():
This method is used to create the object of the HSSFCellStyle. This object is
created to set the cell style.
setDataFormat():
This method is used to set the format of the cellstyle.
getBuiltinFormat():
This method is used to build the format which will be passed into setDataFormat()
to set the format for cell style.
To add date into cells, create new date object and pass directly
into setCellValue() method. At last set these in cell style.
The code of the program is given below:
<%@ page import="org.apache.poi.hssf.usermodel.HSSFSheet"%>
|
The output of the program is given below: