In this program, we are going to pass various data types into the cells and rows in the excel sheet using java .You can create any number of cells and rows and also you can pass different data type values into cells.
The package we need to import is :
org.apache.poi.hssf.usermodel.HSSFRow class is used to create rows in which we can set the cells and add the values.
org.apache.poi.hssf.usermodel.HSSFCell class is used to create a new cell and add the values into cells.
This method is used to create a new row. The argument "value" (short type) is the number for which we are going to create
the row e.g. createRow((short)2) is for creating 2th row.
This method is used to create a new cell. The argument "value" (short type) is the number for which we are going to create the new cell e.g. createCell((short)0) is for creating 0th cell.
This method is used to add the value into the cell. You can add any data types into cell by using this method. In this example, we have used four data types int , float , string and boolean which are being added at 0th ,1st,2nd,3th and 4th cells into 2th row.
In this example, at 0th cell we are passing float values ,at 1st cell we are passing date, at 2nd cell we are passing string ,at 3rd cell we are passing boolean value and at 4th position we are passing HSSFCell.CELL_TYPE_ERROR it will be null value as no error will occur.
The code of the program is given below:
The output of the program is given below:
Posted on: May 19, 2007 If you enjoyed this post then why not add us on Google+? Add us to your Circles