Excel
Spring supports two libraries for generating Excel spreadsheets as views: the Jakarta POI
library and JExcel. Both are used in exactly the same way other than the choice of JAR file that
you add to your WEB-INF/libdirectory in the deployed application and the actual manner of
manipulating the workbook in Java. We’ll look at an example of how to use the POI library
here.
Creating the Template
Creating an Excel spreadsheet is best done from a template, having your model values update
certain cells within that template, which will perhaps be the subject of charts or formulae
already built in to the XLS template file. Merging your model with the template is done in the
same way as we’ve seen for XSLT and PDF Views—by coding a concrete extension to a Spring
provided abstract class.
Figure 8-9 displays the template file that we’ve created for the basis for our view. Model
data will be used to update this template, providing a nicely formatted view to our users. We’ll
store this template in our WAR file at WEB-INF/excel/home.xls.
Figure 8-9.Excel template used to display flights
258 CHAPTER 8 ■SUPPORTED VIEW TYPES