2009/10/26 veena pandit <[email protected]>:
> I am doing exactly what the sample code you are pointing to says to do.
> But it does not open up the xls file in the browser. It opens an empty
> sheet.
Well, no it won't because the code you are writing is running on the
server and will therefore open the file on the server. If you want to
feed it to the browser, you need to write it out to the servlet
response's output stream.
So in practice, you need something like:
String path = "c://downloads//" + "test.xls";
response.setHeader("Content-disposition", "inline;filename="+path);
InputStream inp = new FileInputStream(path);
hssfWorkBook = new HSSFWorkbook(inp);
OutpurSteam out = res.getOutputStream();
wb.write(out);
where res is the HttpServletResponse passed to the servlet's doGet or
doPost method. You will also need to set the content type header to
the correct MIME type.
However, if the only thing you are trying to do is to stream an
existing Excel file to a browser without modification you don't need
POI for this, you just need to copy the content of the InputStream to
the OutputStream.
Bruno
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]