ZipEntry & POI HSSF (XLS Format)
843841Mar 31 2003 — edited Aug 31 2005All,
Currently I have a web application which does the following:
a. Generates data in the POI HSSF XLS format
b. Stores these to disk in a temporary repository
The user can then select reports/HSSF files of interest and these are:
a. Added to a zip entry and stored to disk
b. The zip file is then read in and sent to the browser for download
My question is given the following code, how can I circumvent the stage where the files are stored to disk by:
a. Creating the HSSF/XLS files in memory
b. Writing the HSSF/XLS files directly to a zip package
c. Stream this zip package via a servlet to the browser
// from a servlet
ServletOutputStream browserOut = response.getOutputStream ();
ZipOutputStream zipOut = new ZipOutputStream();
for (int i = 0; i < dataSet.length; i++) {
HSSFWorkbook book = new HSSFWorkbook();
// add a bunch of data to the book, rows, cells, etc...
ZipEntry entry = new ZipEntry (dataSet.someName());
zipOut.putNextEntry (entry);
zipOut.write (?? where ??);
book.write (?? where ??);
browserOut.write (?? where ??);
}
I suppose the heart of the question is: without having an inputstream of an existing file, how can I write an HSSF file format using "someBook.write (OutputStream)" in memory directly to a ZipOutputStream. Then how can I link this ZipOutputStream to a ServletOutputStream so that it's sent to the browser?
Thank you in advance for your help!