Using Apache POI (HSSF) API to create and write an Excel File

import java.io.*;

import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

public class ExcelHandler
{


public ExcelHandler()
{

try {
Workbook wb = new HSSFWorkbook();
CreationHelper createHelper = wb.getCreationHelper();
   FileOutputStream fileOut = new FileOutputStream("D:\\Deepu\\Amul\\workbook.xls");  
   Sheet sheet = wb.createSheet("Data");
 
   Row row = sheet.createRow((short)0);
   // Create a cell and put a value in it.
   Cell cell = row.createCell(0);
   cell.setCellValue("Here We Go !!!");

   // Or do it on one line.
//    row.createCell(1).setCellValue(1.2);
//    row.createCell(2).setCellValue(
//         createHelper.createRichTextString("This is a string"));
//    row.createCell(3).setCellValue(true);

   // Write the output to a file
 
   wb.write(fileOut);
   fileOut.close();
 
 
} catch (Exception e) {
   e.printStackTrace();
}


}



}

1 comment:

  1. Casino Poker - No Limit Poker
    Our new Poker site is built 토토 분석 사이트 around an easy to navigate bet 분석 web-based 텐벳 poker website, where players 카카오스포츠 can bet without 딥 슬롯 any restrictions or fees. In addition, they can

    ReplyDelete