Hi all,
in my project, I have to use rap 1.4.2 and IE6, and I want to use apache poi to generate ms excel file from the database and export excel file in IE6. My code works well in any other browsers except MS IE6. and the snippet just like below:
public void run() {
RWT.getServiceManager().registerServiceHandler( EXCEL_SERVICE_HANDLER, new ExcelServiceHandler("projects.xls") );
RWT.getSessionStore().setAttribute( EXCEL_KEY, ProjectStatisticsToExcelResourse.getExcelContent(projectTypes) );
URL url;
try {
url = new URL(createPDFUrl(EXCEL_KEY));
PlatformUI.getWorkbench().getBrowserSupport().createBrowser("DownloadDialog").openURL(url);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (PartInitException e) {
e.printStackTrace();
}
}
private String createPDFUrl( String string ) {
StringBuffer url = new StringBuffer();
url.append(URLHelper.getURLString());
url.append( "?" );
url.append( IServiceHandler.REQUEST_PARAM );
url.append( "=" );
url.append( EXCEL_SERVICE_HANDLER );
url.append( "&nocache=" );
url.append( System.currentTimeMillis() );
String encodedURL = RWT.getResponse().encodeURL( url.toString() );
return encodedURL;
}
InputStream in = (InputStream) RWT.getSessionStore().getAttribute(
"excelKey");
HttpServletResponse response = RWT.getResponse();
response.setContentType("application/vnd.ms-excel");
String contentDisposition = "attachment; filename=" + fileName;
response.setHeader("Content-Disposition", contentDisposition);
response.setHeader("Content-Transfer-Encoding", "binary");
// response.setHeader("Pragma", "no-cache");
// response.setHeader("Cache-Control", "no-cache, must-revalidate");
//response.setContentLength(in.available());
ByteArrayOutputStream bos = new ByteArrayOutputStream();
int next = in.read();
while (next > -1) {
bos.write(next);
next = in.read();
}
bos.flush();
byte[] result = bos.toByteArray();
try {
ServletOutputStream out = response.getOutputStream();
out.write(result);
out.flush();
} catch (IOException e) {
e.printStackTrace();
}
and the attachment is the project archive file.
thank you very much
David
[Updated on: Mon, 12 November 2012 10:21]
Report message to a moderator