Search code examples
javajspapache-poipoi-hssf

Is there a way to display a HSSFWorkbook Object in a JSP page?


Is there a way to Display a HSSFWorkbook Object in a JSP page without having an output file in the server side? In the code below I am providing the template file and the beans required for net.sf.jxls.transformer.XLSTransformer.transformXLS(InputStream is, Map beanParams) to return me a HSSFWorkbook object. I now need a way to use this object in a JSP without having to store the output file in the server side using OutputStream.

InputStream is = new BufferedInputStream(new FileInputStream(templateFileName));
HSSFWorkbook hm = transformer.transformXLS(is, beans);
req.getSession().setAttribute("excelWorkBook",hm);

Solution

  • Looks simple, write the HSSFWorkbook using the write method on your instance;

    HSSFWorkbook#write(OutputStream)
    

    where the output stream is the;

    response.getOutputStream()
    

    Youll probably want to do things like set the ContentType of the reponse as well as maybe some content dispostion attributes.