Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Excel file generated by poi can not been downloaded in IE6?
Excel file generated by poi can not been downloaded in IE6? [message #981254] Mon, 12 November 2012 04:24
Song David is currently offline Song David
Messages: 185
Registered: April 2011
Senior Member
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 05:21]

Report message to a moderator

Previous Topic:Problem with RWT-OSGi integration bundle on JBoss 7.2
Next Topic:FilteredTree not working correctly for custom TreeViewer
Goto Forum:
  


Current Time: Thu Jul 24 19:05:23 EDT 2014

Powered by FUDForum. Page generated in 0.01921 seconds