Are you serving your data from a servlet or from a JSP ?

Compare the number of bytes written on the server side and the number
of bytes received by the client. Are they equal?

AFAIK, calling  output.flush(); and  output.close(); on a response
output stream is illegal, the stream is flushed and closed
automaticaly by the servlet container.

Yegor

On Thu, Jun 14, 2012 at 8:13 AM, Lokesh Puri <[email protected]> wrote:
> While running the below mentioned code , I am getting the "unreadable
> content" Dialog Box. It says
>
> Excel found unreadable content in 'filename.xlsx' Do you want to recover
> the contents of this workbook? If you trust the source of this workbook,
> click Yes.
>
>
> 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);
> }
>
> P.s. I have followed all the steps mentioned in
> http://apache-poi.1045710.n5.nabble.com/problem-opening-excel-2007-created-using-SXSSF-td4705693.html#a4879769
> but still haven't got rid of this dialog box.
>
>
>
>
>
> --
> View this message in context: 
> http://apache-poi.1045710.n5.nabble.com/Unreadable-Content-using-XSSF-POI-3-8-while-writing-to-response-getOutputStream-tp5710172.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]
>

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

Reply via email to