How to create a sheet using POI?

How to create a sheet using POI?

Previous Home Next

 

In this page of the example we are going to show you how we can create the excel sheet by help of the POI API in java language. for creation of this sheet we are using some method of the POI. firstly we create the object of HSSFWorkbook. then create the fileoutputstream for passing the file name and at last Write the FileOutputStream to workbook object.


 

Firstly we create the object of HSSFWorkbook. then create the fileoutputstream for passing the file name and at last Write the FileOutputStream to workbook object.

 
package r4r;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.hssf.model.Workbook;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
//import org.apache.poi.ss.usermodel.Workbook;
public class POINewWorkbookCreate {
	public static void main(String[] args) throws IOException {
		// Create a workbook object.
		HSSFWorkbook book = new HSSFWorkbook();
		// Create a FileOutputStream by passing the excel file name.
		FileOutputStream outStream = new FileOutputStream("POINewWorkbookCreate.xls");
		// Write the FileOutputStream to book object.
		workbook.write(outStream);
		// Close the FileOutputStream.
		outputStream.close();
		System.out.println("Sheet is created");
	}
}

Sheet is created
Previous Home Next