Monday 13 May 2013

Add Apache-poi jar file into a project in Eclipse and Create Excel sheet



1.Browse the URL as http://poi.apache.org/
2.Click on downoads link
3.Click on The latest stable release is Apache POI 3.9 link
4.Clcik on the poi-bin-3.9-20121203.zip
5.Extract the zip file and Add the poi-3.9-20121203 jar file into a project

Write the below script for Excel sheet creartion


import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class excel {
public static void main(String[] args) throws IOException {
Workbook wb = new XSSFWorkbook();
            //Create sheet as 'newsheet'
   Sheet sh1=wb.createSheet("newsheet");
           //Create sheet as '2ndsheet'
   Sheet sh2=wb.createSheet("2ndsheet");
   FileOutputStream fileOut = new FileOutputStream("kalyan.xlsx");
   wb.write(fileOut);
   fileOut.close();
}

}

Please go through the below link for more examples:
http://poi.apache.org/spreadsheet/quick-guide.html

No comments:

Post a Comment