Dean,

Excel is a very exact and binary format.

You must put out no whitespace from your JSP (I recommend using a servlet, but..)

Change the top part to this:

<%@ page language="java"
%><%@ page
import ="java.util.*,java.io.OutputStream,org.apache.poi.hssf.usermodel.*"
%><%

And make sure you don't have a trailing blank after the final %>

Regards,
Dave

On May 27, 2008, at 4:19 PM, Dean Schulze wrote:


I have a JSP that creates a CSV file, which works. When I convert the JSP page to use HSSF instead it produces no output. The JSP just produces a blank page. With the CSV output the blank JSP popups up and is replaced by the Dialog to
open or save the .csv file.

My JSP is below.

And yes, I have verified that the two header and records Lists contain data.

Thanks.

Dean



<%@ page language="java" %>
<%@ page
import ="java.util.*,java.io.OutputStream,org.apache.poi.hssf.usermodel.*" %>
<%
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition","attachment; filename=browselist.xls");

List headers =(List)request.getAttribute("headers");
List records =(List)request.getAttribute("records");

HSSFWorkbook wb =  new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet();

HSSFFont headerFont = wb.createFont();
headerFont.setFontName(HSSFFont.FONT_ARIAL);
headerFont.setFontHeightInPoints((short) 10);
headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);


HSSFCellStyle HeaderStyle = wb.createCellStyle();
HeaderStyle.setFont(headerFont);

int rowNum = 0;

if (headers != null) {
        
        HSSFRow headerRow = sheet.createRow(rowNum++);
        Object[] arr = headers.toArray();
        
        for (int i=1; i<arr.length; i++) {
                
                String s = (String)arr[i];
                HSSFCell cell = headerRow.createCell((short)i);
                cell.setCellValue(s);
        }
}

if (records != null) {
        
        Object[] arr = records.toArray();
        
        for (int i=0; i<arr.length; i++) {

                String record = (String)arr[i];
                HSSFRow recordRow = sheet.createRow(rowNum++);
                
                StringTokenizer st = new StringTokenizer(record,"|");
                boolean skip = true;
                short cellNum = 0;
                
                while (st.hasMoreTokens()) {
                        
                        String tok=st.nextToken();
                        if (skip) {
                                skip = false;
                                continue;
                        }
        
                        if(tok.equals("&nbsp;"))
                                tok="";
                        
                        HSSFCell cell = recordRow.createCell(cellNum++);
                        cell.setCellValue(tok);
                }
        }
}

OutputStream sos = response.getOutputStream();
wb.write(sos);
sos.close();

%>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to