• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

download to excel in a zip file

 
ank Gupta
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

We have a download to excel feature where user can download data in excel format. We are using JSF framework but since this feature as such is not related to JSF i am asking it in servlets. TYhe problem is that file size is getting heavy (around 40 mb), so user is not able to download it properly getting errors like (the server returned an invalid or unrecognized response) or (page cannot be displayed.) sometimes download box dissappears while downloading .

We have same data in our development and testing env where its working fine. Can somebody suggest some solution? I was thinking of converting that excel to zip file . Is it possible. need help.

Here is a code snippet for download to excel.

public boolean exportToExcel(ArrayList<ExportToExcelVO> listVO,
String fileName, String fileHeading, HttpServletResponse response) {

final LoggerImpl logger = new LoggerImpl(ExportToExcelBean.class);
ExportToExcelVO vo;
boolean result = false;
String contentType = "application/vnd.ms-excel";
response.setHeader("Content-disposition", "attachment; filename="
+ fileName);
response.setContentType(contentType);
try {
PrintWriter out = response.getWriter();
out.println("<html><body><br>");
if (!(fileHeading.equalsIgnoreCase(""))) {
out.println(fileHeading + "<br><br>");
}
for (int k = 0; k < listVO.size(); k++) {
vo=listVO.get(k);
if (!(vo.getStrHeading().equalsIgnoreCase(""))) {
out.println(vo.getStrHeading()+"<br><br>");
}
if (!(vo.getStrTableHeading().equalsIgnoreCase(""))) {
out.println(vo.getStrTableHeading());
}
out.println("<hr><br><table border='1' cellpadding='1' cellspacing='1'>");
for (int i = 0; i < vo.getListRowsToExcel().size(); i++) {
out.println("<tr>"+vo.getListRowsToExcel().get(i)+"</tr>");
for (int j = 0; j < vo.getNoOfRowsBetweenRows(); j++) {
out.println("<br>");
}
out.println("</tr>");
}
out.println("</table>");
out.println("<br><br><br>");
}

out.println("</html></body>");
out.close();
} catch (IOException e) {
logger.error("IO EXCEPTION in Export To Excel Bean");
e.printStackTrace();
result = false;
}
return result;
};


and this code is called from following code :
ExportToExcelVO vo = new ExportToExcelVO();
ExportToExcelBean expExclBean = new ExportToExcelBean();
ArrayList<ExportToExcelVO> listVO = new ArrayList<ExportToExcelVO>();

// lisrRows contains all the data to be exported to excel.

vo.setListRowsToExcel(listRows);
listVO.add(vo);
FacesContext fc = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) fc
.getExternalContext().getResponse();
expExclBean.exportToExcel(listVO, fileName, fileHeader, response);
fc.responseComplete();
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic