package com; import java.io.File; import java.io.FileOutputStream; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFCellStyle; import org.apache.poi.hssf.usermodel.HSSFFont; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; public class WriteToExcelFromPOI { HSSFFont fontHeading=null; HSSFCellStyle styleHeading=null; public void generateReport(){ HSSFWorkbook wb = new HSSFWorkbook(); fontHeading=wb.createFont(); styleHeading=wb.createCellStyle(); styleHeading=getStyleHeadLine(styleHeading,fontHeading); HSSFSheet sheet=wb.createSheet("TestSheet"); HSSFRow row=sheet.createRow(0); HSSFCell cell=row.createCell((short)0); row.setHeight((short)(3*256)); cell.setCellValue("This is cell content.."); cell.setCellStyle(styleHeading); String filePath="C:\\Ravi\\abc.xls"; try { File file=new File(filePath); FileOutputStream fos=new FileOutputStream(file); wb.write(fos); System.out.println("File has been created in "+filePath); } catch (Exception e) { System.out.println("Errors occured while creating the file."); e.printStackTrace(); } }//public void generateReport(.. private HSSFCellStyle getStyleHeadLine(HSSFCellStyle style, HSSFFont font){ font.setColor((short)32); //DARKBLUE font.setFontHeight((short)(9*20)); font.setFontName("Verdana"); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); style.setWrapText(true); style.setFont(font); style.setAlignment(HSSFCellStyle.ALIGN_CENTER); return style; }//getStyleHeadLine.. public static void main(String[] args) { WriteToExcelFromPOI obj=new WriteToExcelFromPOI(); obj.generateReport(); } }//public class TrainingDataExcelReportPOI