Skip to main content

Play framework 1.2.x excel export with I18n and custom filename

play-excel is a very well written plugin of Play-framework for exporting excel from java objects.

I used this plugin for my requirement of generating the I18n supported xls with custom names. This blog will explain this in details so that I can use it later :).

Line# 4: will basically make the play-excel to take the rendering functionality in play. (you can also use xlsx instead of "xls")

Line# 5: Will set the exported filename to given name i.e. "downloadUsers.xls"

Line# 6&7: pick up the template from views//users_.xls.

2.  public static void users() {
3.          List users = User.findAll();
4.          request.format = "xls";
5.          renderArgs.put("__FILE_NAME__", "downloadUsers.xls");
6.          String template = "users-" + Lang.get() + ".xls";
7.          renderTemplate(template, users);
8.    }
That's it you are done. Happy coding :).


Popular posts from this blog Connection reset

I am able to fix the problem via setting the following params on the HTTPClient class... client.getParams().setParameter("http.socket.timeout", new Integer(0)); client.getParams().setParameter("http.connection.stalecheck", new Boolean(true)); Connection reset at Source) at Source) at Source) at org.apache.commons.httpclient.HttpParser.readRawLine( at org.apache.commons.httpclient.HttpParser.readLine( at org.apache.commons.httpclient.HttpConnection.readLine( at org.apache.commons.httpclient.HttpMethodBase.readStatusLine( at org.apache.commons.httpclient.HttpMethodBase.readResponse( at org.apache.commons.httpclient.HttpMethodBase.execute(

Write a Java program to read console data using bufferedreader API

BufferedReader is a class which simplifies reading text from a character input stream. It buffers the characters in order to enable efficient reading of text data. The buffer size may be specified, or the default size may be used. The default is large enough for most purposes. In general, each read request made of a Reader causes a corresponding read request to be made of the underlying character or byte stream. It is therefore advisable to wrap a BufferedReader around any Reader whose read() operations may be costly, such as FileReaders and InputStreamReaders. For example, // BufferedReader in = new BufferedReader(new FileReader("")); will buffer the input from the specified file. Without buffering, each invocation of read() or readLine() could cause bytes to be read from the file, converted into characters, and then returned, which can be very inefficient. import; import; import

Hide empty last column from Table/Tree Viewer

1. How to remove last vestigial column from TableViewer You might have seen that there is dummy or vestigial column in the TableViewer (as marked by the red oval in the below figure) which  is annoying at times because not only it look ugly but more so it occupy;s the precious  real state from your component/control like shown in figure below: Solution: You can use  TableColumnLayout from  org.eclipse.jface.layout package inside  org.eclipse.jface plugin which allows to layout the columns in your TableViewer in essentially two ways: Firstly via mentioning the width in pixel for each column present in the Viewer  Secondly, we could mentioned weights The data could be supplied to the layout via of the implementation of  ColumnLayoutData. The following snippet shows how to achieve it: tableColumnLayout.setColumnData(tableColumn, new ColumnWeightData(1)); Explanation of the above line: tableColumnLayout is   instance of  ColumnLayoutData tableColumn is the column on which