hi dear vinamra.singhai

 i got this error but i am able to generate large excel file using this
Export.java file

y cant u try it in ur code u r trying to generate new spread sheet i
suppose plzz go thre this code

good luck



package com.vl.hr.reports.action;

import java.util.ArrayList;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.log4j.Logger;
import com.vl.hr.reports.values.Lists;

 class Export
{
 private static Logger log = Logger.getLogger(Export.class);
 //creating a workbook;
 HSSFWorkbook wb = new HSSFWorkbook();
  public HSSFWorkbook exportExcel(Lists lists, ArrayList list2, String
title)
 {
  String[] outputs=lists.getOutputs();
  String[] outputTypes=lists.getOutputTypes();


  ArrayList al=list2;
  try{
    //creating a worksheet
    HSSFSheet sheet=wb.createSheet("First sheet");

    HSSFCellStyle cs = wb.createCellStyle();
    HSSFCellStyle cs2 = wb.createCellStyle();
    HSSFCellStyle cs3 = wb.createCellStyle();
    // create 2 fonts objects
    HSSFFont f = wb.createFont();
    HSSFFont f2 = wb.createFont();

    //set font 1 to 12 point type
    f.setFontHeightInPoints((short) 12);
    //make it red
    f.setColor((short) HSSFColor.RED.index);
    // make it bold
    //arial is the default font
    f.setBoldweight(f.BOLDWEIGHT_BOLD);
    //creation of the row for Titles
    HSSFRow row=sheet.createRow(0);

    //for loop, creating cell headings
    for(int i=0;i<outputs.length;i++)
    {
     HSSFCell cell=row.createCell((short)i);
     //set cell stlye
           cs.setFont(f);
     HSSFRichTextString str=new HSSFRichTextString(outputs[i]);
     cell.setCellValue(str);
    }
    int size = list2.size();
    for(int i=0;i<size;i++)
    {
     row=sheet.createRow(i+1);

     //creating a arraylist for internallists
     ArrayList al2=(ArrayList)list2.get(i);
     int al2size = al2.size();
     for(int j=0;j<al2size;j++)
     {
      HSSFCell cell=row.createCell((short)j);

      if(outputTypes[j].equals("String")){
       cell.setCellValue((String)al2.get(j));
      }
      else if(outputTypes[j].equals("double")){
       cell.setCellValue(((Double)al2.get(j)).doubleValue());
      }
      else if(outputTypes[j].equals("long")){
       cell.setCellValue(((Long)al2.get(j)).longValue());
      }
      else if(outputTypes[j].equals("Date")){
       cell.setCellValue((String)al2.get(j));
      }
     }
    }
  }catch(Exception e)
  {
   log.error("Error writing the Excel file");
   log.debug(e.getMessage());

  }
  return wb;
 }

}

Reply via email to