Hi Yegor,

I have done all the steps mentioned forum post but I am still getting the
same "unreadable content" Dialog Box. I am using POI-3.8 and have Excel 2007
installed on my machine. My code works fine and xlsx opens without issues if
I write to FileOutputStream as mentioned in one of the posts earlier while
if I write to response.getOutputStream(), I get "unreadable content" dialog
box. Please find my code snippet below, I am not doing anything fancy just
writing 70k lines to xlsx.

My Controller Code

response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setHeader("Content-Disposition","attachment;filename=" + fileName);
service.createPOCDoc(response.getOutputStream());

My Service Code

public void createPOCDoc(OutputStream output) throws IOException{
                Workbook wb = new XSSFWorkbook();
                createDataSheet(wb.createSheet("data"), 70000);
                wb.write(output);
                output.flush();
                output.close();
}
        
private void createDataSheet(Sheet sheet, int max_rows) {

                for (int i = 0; i < max_rows; i++) {
                        Row row = sheet.createRow(i);
                        Cell cell = row.createCell(0);
                        cell.setCellValue("row number - " + i);
                }

                System.out.println("added " + max_rows);
}


Yegor Kozlov-4 wrote
> 
> Your servlet must return "application/vnd.ms-excel" for .xls and
> "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
> for .xlsx files. Please ensure you set it correctly.
> 
> Yegor
> 
>  View this message in context:
> http://apache-poi.1045710.n5.nabble.com/problem-opening-excel-2007-created-using-SXSSF-tp4705693p4879718.html
> 
> 


--
View this message in context: 
http://apache-poi.1045710.n5.nabble.com/problem-opening-excel-2007-created-using-SXSSF-tp4705693p5710150.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to