Export JSF Datatable to Excel

Lately I’ve committed a new component to the MyFaces Sandbox. It’s called ExcelExport and used to export the contents of a datatable as a regular excel file using Apache POI. The component must have a child that has onclick attribute, following is an example using a command button.

<s:excelExport for=”tableIdHere”>
<h:commandButton value=”Export” />

Also the example in myfaces repo:

For now it only works with server side state saving, using ajax and sending the view with the ajax request I’ll make the component start working with the client side state saving too. In my old project I’ve embedded this feature to the datatable itself by placing an excel icon on the top-right corner. The screenshots of my old work is here. The one I’ve added to myfaces sandbox is more flexible since it can be used with different types of child components, actually the idea behind the scenes is same but the usage is different.

Update(06 May 2009): For the ultimate JSF export datatable(excel, pdf, csv, xml) experience see PrimeFaces Exporter.


5 Responses to Export JSF Datatable to Excel

  1. Hey C!

    don’t care that much about client side state saving 🙂 You know the numbers…

    but that component is def. nice!


  2. lingoosoft says:


    I think I found a bug of s:excelExport.

    In my jsf page, used two dataTable with “rendered” attribute and only one dataTable could display at the same time.

    The two dataTable with the same value of “id” attribute.

    When the first dataTable displayed, the s:excelExport worked well; but the second displayed, the s:excelExport caused the exception.

  3. Anonymous says:

    Does not work when the number of columns inside a dataTable is dynamic??

%d bloggers like this: