JExcel API can't output file from a servlet

import java.io.IOException;

import java.io.OutputStream;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import jxl.Workbook;

import jxl.write.Label;

import jxl.write.WritableSheet;

import jxl.write.WritableWorkbook;

publicclass Sampleextends HttpServlet

{

publicvoid doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException

{

OutputStream out =null;

try

{

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

response.setHeader("Content-Disposition","attachment; filename=sampleName.xls");

WritableWorkbook w = Workbook.createWorkbook(response.getOutputStream());

WritableSheet s = w.createSheet("Demo", 0);

s.addCell(new Label(0, 0,"Hello World"));

w.write();

w.close();

}catch (Exception e)

{

thrownew ServletException("Exception in Excel Sample Servlet", e);

}finally

{

if (out !=null)

out.close();

}

}

}

I am trying to create a generic class that can export database table to excel files. But the problem is Workbook.createWorkbook(OuputStream) only take in outputstream. I can't pass the outputstream over to servlet for the user to download.

Anyone can help?

[2714 byte] By [liangtehza] at [2007-11-27 11:42:42]
# 1

As far as I can see, the code you posted will send the worksheet you produced to the browser. In other words, to me it appears to be the answer to your question. So obviously I don't understand your question. Could you rephrase or clarify it?

DrClapa at 2007-7-29 17:45:42 > top of Java-index,Java Essentials,Java Programming...
# 2

I do the formatting, inserting of the values to the workbook at another java class and I wish to pass the Object over to servlet to output as file.

liangtehza at 2007-7-29 17:45:42 > top of Java-index,Java Essentials,Java Programming...