output ArrayList to excel in jsf

Hi,

I want to show an arraylist (or a string with data if arraylist is not possible) in excel format within my jsf page, but i don't want to save the data to a file first... is this possible?

I've tried to do the following, but the data is not what i wanted...

public String generateExcelOutput(List list){

ByteArrayOutputStream byteArrayOutputStream =new ByteArrayOutputStream();

ObjectOutputStream objectOutputStream;

try{

objectOutputStream =new ObjectOutputStream(byteArrayOutputStream);

objectOutputStream.writeObject(list);

}catch (IOException e){

thrownew FacesException(e);

}

byte[] excelData = byteArrayOutputStream.toByteArray();

FacesContext faces = FacesContext.getCurrentInstance();

HttpServletResponse response = (HttpServletResponse) faces.getExternalContext().getResponse();

response.setContentType("application/vnd.ms-excel");

response.setContentLength(excelData.length);

try{

ServletOutputStream out;

out = response.getOutputStream();

out.write(excelData);

}catch (IOException e){

thrownew FacesException(e);

}

faces.responseComplete();

returnnull;

}

--> a popup disappears with the question to save or open...that's correct but i also get a notice that the file is corrupt and the data is not shown as it should be...

Can anyone help me, perhaps with an example...

Thanks!

[2238 byte] By [javaantjea] at [2007-11-26 16:20:23]
# 1

By using jakarta-poi, output the workbook like this...

HSSFWorkbook generatedExcel = null;

generatedExcel = generateExcel(blah blah);

generatedExcel.write(response.getOutputStream());

If you are trying to export your datatables to excel, use excelcreator

http://sourceforge.net/project/showfiles.php?group_id=137466&package_id=188186

mulderbabaa at 2007-7-8 22:43:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...