GWT Open .CSV Document in Excel without saving file at server side.

596 views
Skip to first unread message

KalyanChakri

unread,
Sep 5, 2012, 10:46:25 AM9/5/12
to google-we...@googlegroups.com
This is a solution Post of how GWT app can launch Excel or other applications and load a file, without saving a file at server end.
The idea to save .csv/Excel resource to hardisk and later delete is more Resource oriented. This pushed me to use above methodology. Not sure if there are other ways to do it.
 

1. Include the following inherit in the .gwt.xml file

<inherits name="com.google.gwt.http.HTTP"/>

2. Create a new Servlet and it should extend HttpServlet class

public class ReadCSV extends HttpServlet{

     String contents = "Hello";

      response.setHeader("Content-Type", "application/vnd.ms-excel");
      response.setHeader("Content-Length", String.valueOf(contents.length()) );
      response.setHeader("Content-Disposition", "attachment; filename=\"" + "CSVReader.CSV" + "\"");
      response.getWriter().write(contents);
      response.getWriter().flush();
      response.getWriter().close();

}

3. On the Click of the button Implement the click Handler and state the following
 
Window.open(GWT.getModuleBaseURL() + < your serlvet name >, "<file name>", "");
Here the parameters can be passed as a QueryString to the Servlet or Use RequestBuilder to create Request Parameters.
 
Hope this information helps all.
 
Thanks,
Kalyan.
 
 

 

Reply all
Reply to author
Forward
0 new messages