Excel Tag Library
How does it works ?
Excel Tag Library is based on
Apache POI 3.7. It uses very simple JSP-Tags to produce an Excel compatible output, ready to be downloaded from yor WEB application.
Installation
You can integrate the source or you can simply
download the jar, drop it in your
WEB-IN/lib directory and add the reference in
web.xml:
<taglib>
<taglib-uri>http://digamma.ch/taglib/excel.tld</taglib-uri>
<taglib-location</WEB-INF/excel.tld</taglib-location>
</taglib>
Usage
Add the reference to the taglibrary on the top of your JSP
<%@ taglib uri="http://digamma.ch/taglib/excel.tld" prefix="xls"%>
An example of a minimal excel file:
<xls:workbook filename="simpleExcel.xls">
<xls:sheet name="First Sheet">
<xls:row>
<xls:cell>Hello, World !</xls:cell>
</xls:row>
</xls:sheet>
</xls:workbook>
Tag library
- <xls:workbook> is the root tag.
Attributes:
- filename, required, is the resulting filename for download. Avoid special characters or empty spaces expecially with Forefox.
- <xls:sheet>, you can have one or more sheets in a workbook.
Attributes:
- name: Optional, is the name of the sheet. If empty, "Sheet_index" will be used.
- <xls:row> a row in a sheet.
Attributes:
- height: Height of the row, in points.
- border: Semicolon separated border definition in form "border":"type".
The values of "border" can be top, bottom, right, left and all.
The values of "type" can be default, thin, medium, thick, dash, hair or none. Note that "none" implies all.
Example: border="top:thin;bottom:dash".
- <xls:cell> a cell in a row.
Attributes:
- align: Horizontal alignment. Values are center, left or right.
- valign: Vertical alignment. Values are center, top or bottom.
- border: Semicolon separated border definition in form border":"type".
The values of "border" can be top, bottom, right, left and all.
The values of "type" can be default, thin, medium, thick, dash, hair or none. Note that none implies all.
Example: border="top:thin;bottom:dash".
If no border is defined, the one of the row will be inherited.
- width: The cell (Column) width in points, or auto for autoformatting. Overwrites previous declaration for the same column.
Troubleshooting
In the page section of the jsp, you
must declare
trimDirectiveWhitespaces="true". This is needed to avoid the JSPWriter to fill up the buffer, and thus conflict later when the Excel Workbook has to be written in the SerlvetOutputStream.
<%@page autoFlush="false" buffer="8kb" trimDirectiveWhitespaces="true"%>