This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes download to excel in a zip file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "download to excel in a zip file" Watch "download to excel in a zip file" New topic
Author

download to excel in a zip file

ank Gupta
Greenhorn

Joined: Jun 20, 2008
Posts: 6
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();
 
Consider Paul's rocket mass heater.
 
subject: download to excel in a zip file
 
Similar Threads
how to extract data to an xl sheet
Upload Download File
Zip and excel generated on the fly
how to extract data from html page to excel sheet
document variable is nullified after servlet file download