Apache Poi Demo
Introduction
Apache poi project provides a jar file of API, by using API’s method we can create , read ,write Microsoft office objects like ms word,excel, power point, visio,outlook.
Download Link
The jar file name that i downloaded for my demo is (poi-3.8-20120326.jar )
http://poi.apache.org/download.html
Configuring in the eclipse
1. Create a java project in eclipse say , ApachePoi.
2. Create a lib folder inside it and then paste the jar file
3. Add this java file to build path.
Java Coding
PoiExcelExample. java file,
package com.sandeep.poi;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class PoiExcelExample {
public static void main(String[] args) {
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("students");
HSSFRow row = sheet.createRow(1);
HSSFCell cell = row.createCell(1);
cell.setCellValue(new HSSFRichTextString("sandeep"));
FileOutputStream fos = null;
try {
fos = new FileOutputStream(new File("D:\myExcelWorkBook.xls"));
workbook.write(fos);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
fos.flush();
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}