Well I got it to work. I had to remove the newline between the <%@ page import
%> and <% HSSF code ... %>.
So my code looks like this:
<%@ page import="org.apache.poi.poifs.filesystem.*,
org.apache.poi.hssf.usermodel.*,
java.io.*,
java.util.*"
%><%
try {
//FileOutputStream out1 = new FileOutputStream("/tmp/gracework.xls");
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet s = wb.createSheet();
HSSFRow r = null;
HSSFCell c = null;
// HSSFCellStyle cs = wb.createCellStyle();
// HSSFDataFormat df = wb.createDataFormat();
wb.setSheetName(0, "one");
for (int rownum=0; rownum<4; rownum++) {
r = s.createRow(rownum);
for (short cellnum=0; cellnum<5; cellnum++) {
c = r.createCell(cellnum);
c.setCellValue(cellnum);
}
}
//response.setContentType("application/octet-stream");
response.setContentType("application/vnd.ms-excel");
//response.setContentType("application/binary");
response.setHeader("Content-Disposition", "attachment; filename=monk.xls");
ServletOutputStream o = response.getOutputStream();
wb.write(o);
o.close();
//wb.write(out1);
//o.flush();
//o.close();
//out.close();
}
catch (Exception e)
{
e.printStackTrace();
}
%>
-----Original Message-----
From: David Henry [mailto:[EMAIL PROTECTED]
Sent: Friday, February 23, 2007 6:30 PM
To: POI Users List
Subject: RE: Unable to display workbook in JSP
I, too, had this problem and ended up just putting my HSSF code into a servlet
and calling it in my JSP. Sorry, no help, but it worked fine this way.
- David
-----Original Message-----
From: Siwicki, Grace [mailto:[EMAIL PROTECTED]
Sent: Friday, February 23, 2007 5:29 PM
To: [email protected]
Subject: Unable to display workbook in JSP
Hi,
I've created a workbook in my JSP and am trying to display the output back in
my JSP. But I am getting junk data displayed in my browser.
Can someone look at my code and tell me what I'm doing wrong?
I've used the same code to write the output to the filesystem and that seems to
work fine but I can't seem to write it back to the browser.
Any help would be appreciated.
Grace
<%@ page import="org.apache.poi.poifs.filesystem.*,
org.apache.poi.hssf.usermodel.*,
java.io.*,
java.util.*"
%>
<%
try {
//FileOutputStream out1 = new
FileOutputStream("/tmp/gracework.xls");
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet s = wb.createSheet();
HSSFRow r = null;
HSSFCell c = null;
// HSSFCellStyle cs = wb.createCellStyle();
// HSSFDataFormat df = wb.createDataFormat();
wb.setSheetName(0, "one");
for (int rownum=0; rownum<4; rownum++) {
r = s.createRow(rownum);
for (short cellnum=0; cellnum<5; cellnum++) {
c = r.createCell(cellnum);
c.setCellValue(cellnum);
}
}
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment; filename=blah.xls");
ServletOutputStream o = response.getOutputStream();
wb.write(o);
o.close();
}
catch (Exception e)
{
e.printStackTrace();
}
%>
========================================================================
======
Please access the attached hyperlink for an important electronic communications
disclaimer:
http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html
========================================================================
======
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
Mailing List: http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta Poi Project: http://jakarta.apache.org/poi/
==============================================================================
Please access the attached hyperlink for an important electronic communications
disclaimer:
http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html
==============================================================================
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
Mailing List: http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta Poi Project: http://jakarta.apache.org/poi/