Using jXLS and jXLSUtiltiy.cfc to export Excel files

In my last post I described the what and why of jXLS. So now let's see what you have to do to use it. I mentioned you will need 2 java packages. The first is the jXLS package itself. The second is one that is required by jXLS, Commons JEXL. See the jXLS installation page for this. There are other required packages, but this is the only one I found I needed (by way of an exception before it was installed). You must also have POI 2.5.1 or higher. On my dev workstation I have CF 7 installed, and that is the version of POI that came with CF. To find out what version you have go to your CF Adminstrator, go to System Information and do a find on "POI". That should show you the .jar file that is installed, including the version number.

Once you've got those installed, grab my jXLS demo files and (see below) unzip them into a directory you can browse to. From there you can open the Exel template file. A partial screen shot can be seen below.

If everything is installed correctly, you should be able to run http://localhost/jXLSDemo/jXLS_ContactsUseCFC.cfm and create the output excel file. Look at the code in that file and the jXLSUtility.cfc to see what is going on. It's pretty straightforward. I also have working, but not included in this zip, a port of the Tags Sample that is included in the jXLS download from Source Forge. It uses Lightweight Transfer Objects instead of a query to generate the data and hashMap.

Next I hope to figure out how to do multiple sheets. I saw some method calls that should handle this, just have not yet attempted it. I also hope to further explore the API of jXLS, though this contacts example and the Tags Sample will get me pretty far in what I need.

Leave a comment if you have any questions. I hope someone else finds this useful. Based on the comments on Ben Nadel's Excel Export posts, there seems to be quite an interest in this type of functionality.

Download Enclosure  ( 8 KB) |  Java Utilities, Excel  |  Send
Posted 3/4/07 @ 6:45 AM by Matt Williams