user1511118
user1511118

Reputation: 31

Unable to generate download excel file on client side usinf poi mvc

I am unable to generate an Excel file for download on the client side. This is the code I have:

 <%
 try{
  //Getting HSSFWorbook object from controller
    HSSFWorkbook wb= (HSSFWorkbook)pageContext.findAttribute("wb");
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-   Disposition","attachment;
    filename=ESTHotelPerfByMonthExcelReport.xls"
    );
  //Writing to output Stream 

    ServletOutputStream outputStream = response.getOutputStream();
    wb.write(outputStream);
    outputStream.flush();
 }//closing try
 catch (IOException ioe) { 
 }
}//closing if


//The above code is not generating any 
// excel sheet however if i write the output to 
// a    excel file it shows the all the data

 %>

Upvotes: 0

Views: 1956

Answers (1)

Alexey A.
Alexey A.

Reputation: 1419

I assume that you are trying to write the generated xls file from a JSP file. The problem might be in the whitespaces, if there are some, then write to ServletOutputStream will produce exception.

So please check that before "<%" there are no whitespace between directives. Also set <%@ page trimDirectiveWhitespaces="true" %> just in case.

Upvotes: 2

Related Questions