Is it true that the retrieveEntireTable method gets the data from the "table"
and creates a HSSFWorkbook object?
If that is the case, then give something like this a try....
private byte[] getBytesFromWorkbook(HSSFWorkbook workbook)
{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try
{
workbook.write(bos);
bos.close();
} catch (IOException ex)
{
ex.printStackTrace();
// Add error handling - probably want to throw this
}
return bos.toByteArray();
}
You can probably get rid of everything except the call to workbook.write(bos).
I may be completely off base, but hopefully it will point you in the right
direction.
---- Julien Martin <[EMAIL PROTECTED]> wrote:
> Hello,
> I have a problem with a dowloaded excel file produced by POI. It says the
> file is damaged...
>
> Here is the method I use in order to download the file:
>
> public String exportEntireTable() {
> FacesContext facesContext = FacesContext.getCurrentInstance();
> if (!facesContext.getResponseComplete()) {
> String fileName = "export.xls";//todo
>
> ServletContext servletContext = (ServletContext)
> facesContext.getExternalContext().getContext();
> String contentType = servletContext.getMimeType (fileName);
>
> HttpServletResponse response = (HttpServletResponse)
> facesContext.getExternalContext().getResponse();
> response.setContentType(contentType);
> response.setHeader("Content-Disposition",
> "attachment;filename=\"" + fileName + "\"");
>
>
> try {
> InputStream in = new
> ByteArrayInputStream(retrieveEntireTable());//returns an array of bytes for
> the file
> //BlockingInputStream bis = new BlockingInputStream(in);
> ServletOutputStream out = response.getOutputStream();
>
> byte[] buf = new byte[512];
> int bytesRead;
> while ((bytesRead = in.read(buf)) != -1) {
> out.write(buf, 0, bytesRead);
> }
>
> out.flush();
> facesContext.responseComplete();
> } catch (IOException e) {
> log.fatal("IOException", e);
> throw new RuntimeException(e);
> }
> }
> return null;
> }
>
> Can anyone please help?
>
> Thanks in advance,
>
> Julien.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]