You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by "Singhai, Vinamra" <vi...@bofasecurities.com> on 2007/04/17 15:31:14 UTC
Problem with LArge Excel Sheet Generation
Hi all,
I am facing problem with generation of excel sheet and I am attaching the
conversation B/W me and Anthony(Large Excel Sheet.zip).
Please go through it and let me know you view. I'd be grateful to you all.
Thanks and Regards,
Vinamra
RE: Problem with LArge Excel Sheet Generation
Posted by "Singhai, Vinamra" <vi...@bofasecurities.com>.
Hi Rajeshwar,
Thanks for the suggestion. I tried your way but I am getting same
java.lang.NullpointerException as I mentioned earlier. I have certain
questions:
1) Do Websphere has any upper limit on the number of objects can be created?
2) I get exception on the line
Export export = new Export();
HSSFWorkbook hssfWB = export.exportExcel(lists, list2,"vinsin");
I get the exception in case of large size of list2.
Thanks and Regards,
Vinamra
-----Original Message-----
From: Rajeshwar Mothe [mailto:rajkishan.m@gmail.com]
Sent: Wednesday, April 18, 2007 8:39 PM
To: POI Users List
Subject: Re: Problem with LArge Excel Sheet Generation
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;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
Mailing List: http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta Poi Project: http://jakarta.apache.org/poi/
Re: Problem with LArge Excel Sheet Generation
Posted by Rajeshwar Mothe <ra...@gmail.com>.
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;
}
}