Help

Built with Seam

You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.

Using Apache POI to generate Excel documents

There have been some people suggesting we should use POI to generate Excel documents in Seam. I don't know POI that well, so instead I'd like to show how you can do it yourself.

First, we add our implementation to components.xml

<excel:excelFactory>
   <property name="implementations">
      <key>poi</key>
      <value>my.POIExcelWorkbook</value>
   </property>
</excel:excelFactory>

Now we have bound poi to my.POIExcelWorkbook. To use this implementation in an Excel workbook we simply need to define type in our jsf workbook page.

<e:workbook type="poi"
   xmlns:e="http://jboss.com/products/seam/excel"
   xmlns:f="http://java.sun.com/jsf/core">
      <e:worksheet name="Developers">
         <e:cell column="0" row="0" value="Daniel Roth" />
	 <e:cell column="0" row="1" value="Nicklas Karlsson" />
      </e:worksheet>
</e:workbook>

Finally we need to implement the ExcelWorkbook interface (yes, this you have to do yourself)

package  my;
public class POIExcelWorkbook implements ExcelWorkbook {}

The ExcelWorkbook interface is very well documented regarding what's going to be done on each call. You may also want to look in CsvExcelWorkbook.java and JXLExcelWorkbook.java for implementation hints.

What about the exporter? Using your own implementation will work fine, since you may add implementation type to use when calling it:

<h:commandButton action="#{excelExporter.export(dataTableId,'poi')}"/>