SeamFramework.orgCommunity Documentation
Seam also supports generation of the Microsoft® Excel® spreadsheet application spreadsheets through the excellent JExcelAPI library. The generated document is compatible with the Microsoft® Excel® spreadsheet application versions 95, 97, 2000, XP and 2003. Currently a limited subset of the library functionality is exposed but the ultimate goal is to be able to do everything the library allows for. Please refer to the JExcelAPI documentation for more information on capabilities and limitations.
the Microsoft® Excel® spreadsheet application jboss-seam-excel.jar. This JAR contains
the the Microsoft® Excel® spreadsheet application JSF controls, which are used to construct views that can
render the document, and the DocumentStore component, which serves
the rendered document to the user. To include the Microsoft® Excel® spreadsheet application support in
your application, included jboss-seam-excel.jar
in your WEB-INF/lib directory along with the
jxl.jar JAR file. Furthermore, you need to
configure the DocumentStore servlet in your web.xml
the Microsoft® Excel® spreadsheet application Seam module requires the use of Facelets as the view technology. Additionally, it requires the use of the seam-ui package.
The examples/excel project contains an example of
the Microsoft® Excel® spreadsheet application support in action. It demonstrates proper deployment
packaging, and it shows the exposed functionality.
Customizing the module to support other kinds of the Microsoft® Excel® spreadsheet application spreadsheet
API's has been made very easy. Implement the ExcelWorkbook
interface, and register in components.xml.
<!-- XML : generated by JHighlight v1.0 (http://jhighlight.dev.java.net) --> <span class="xml_plain"></span><br /> <span class="xml_plain"> </span><br /> <span class="xml_plain"> </span><span class="xml_tag_symbols"><</span><span class="xml_tag_name">excel:excelFactory</span><span class="xml_tag_symbols">></span><span class="xml_plain"></span><br /> <span class="xml_plain"> </span><span class="xml_tag_symbols"><</span><span class="xml_tag_name">property</span><span class="xml_plain"> </span><span class="xml_attribute_name">name</span><span class="xml_tag_symbols">=</span><span class="xml_attribute_value">"implementations"</span><span class="xml_tag_symbols">></span><span class="xml_plain"></span><br /> <span class="xml_plain"> </span><span class="xml_tag_symbols"><</span><span class="xml_tag_name">key</span><span class="xml_tag_symbols">></span><span class="xml_plain">myExcelExporter</span><span class="xml_tag_symbols"></</span><span class="xml_tag_name">key</span><span class="xml_tag_symbols">></span><span class="xml_plain"></span><br /> <span class="xml_plain"> </span><span class="xml_tag_symbols"><</span><span class="xml_tag_name">value</span><span class="xml_tag_symbols">></span><span class="xml_plain">my.excel.exporter.ExcelExport</span><span class="xml_tag_symbols"></</span><span class="xml_tag_name">value</span><span class="xml_tag_symbols">></span><span class="xml_plain"></span><br /> <span class="xml_plain"> </span><span class="xml_tag_symbols"></</span><span class="xml_tag_name">property</span><span class="xml_tag_symbols">></span><span class="xml_plain"></span><br /> <span class="xml_plain"> </span><span class="xml_tag_symbols"></</span><span class="xml_tag_name">excel:excelFactory</span><span class="xml_tag_symbols">></span><span class="xml_plain"></span><br /> <span class="xml_plain"> </span><br /> <span class="xml_plain"> </span><br />
and register the excel namespace in the components tag with
<!-- XML : generated by JHighlight v1.0 (http://jhighlight.dev.java.net) --> <span class="xml_plain"></span><br /> <span class="xml_plain"> </span><br /> <span class="xml_plain"> xmlns:excel="http://jboss.com/products/seam/excel"</span><br /> <span class="xml_plain"> </span><br /> <span class="xml_plain"> </span><br />
Then set the UIWorkbook type to myExcelExporter and your
own exporter will be used. Default is "jxl", but support for CSV has also been
added, using the type "csv".
Basic usage of the worksheet support is simple; it is used like a
familiar <h:dataTable> and you can bind to a
List, Set,
Map, Array or
DataModel.
<e:workbook xmlns:e="http://jboss.com/products/seam/excel">
<e:worksheet>
<e:cell column="0" row="0" value="Hello world!"/>
</e:worksheet>
</e:workbook>
That's not terribly useful, so lets have a look at a more common case:
<e:workbook xmlns:e="http://jboss.com/products/seam/excel">
<e:worksheet value="#{data}" var="item">
<e:column>
<e:cell value="#{item.value}"/>
</e:column>
</e:worksheet>
</e:workbook>
First we have the top-level workbook element which serves as the container and it doesn't have any attributes. The child-element worksheet has two attributes; value="#{data}" is the EL-binding to the data and var="item" is the name of the current item. Nested inside the worksheet is a single column and within it you see the cell which is the final bind to the data within the currently iterated item
This is all you know to get started dumping your data to worksheets!
Workbooks are the top-level parents of worksheets, cell templates and worksheet templates.
|
|
Attributes
Child elemenents
Facets
|
<e:workbook>
<e:worksheet>
<e:cell value="Hello World" row="0" column="0"/>
</e:worksheet>
<e:workbook>
defines a workbook with a worksheet and a greeting at A1
Worksheets are the children of workbooks and the parent of columns and worksheet commands They can also contain explicitly placed cells, formulas, images and hyperlinks. They are the pages that make up the workbook.
|
|
Child elemenents
Facets
|
<e:workbook>
<e:worksheet name="foo" startColumn="1" startRow="1">
<e:column value="#{personList}" var="person">
<f:facet name="header">
<e:cell value="Last name"/>
</f:facet>
<e:cell value="#{person.lastName}"/>
</e:column>
</e:worksheet>
<e:workbook>
defines a worksheet with the name "foo", starting at B2.
Columns are the children of worksheets and the parents of cells, images, formulas and hyperlinks. They are the structure that control the iteration of the worksheet data.
|
|
Attributes
Child elemenents
Facets
|
<e:workbook>
<e:worksheet>
<e:column value="#{personList}" var="person">
<f:facet name="header">
<e:cell value="Last name"/>
</f:facet>
<e:cell value="#{person.lastName}"/>
</e:column>
</e:worksheet>
<e:workbook>
defines a column with a header and an iterated output
Cells are nested within columns (for iteration) or inside worksheets
(for direct placement using the column and
row attributes) and are responsible for outputting
the value (usually though en EL-expression involving the
var-attribute of the datatable. They can contain
fonts and other formattings and can also use pre-defined templates.
|
|
Attributes
Child elemenents
Facets
|
<e:workbook>
<e:worksheet>
<e:column value="#{personList}" var="person">
<f:facet name="header">
<e:cell value="Last name"/>
</f:facet>
<e:cell value="#{person.lastName}"/>
</e:column>
</e:worksheet>
</e:workbook>
defines a column with a header and an iterated output
Fonts are nested inside cells, formulas, hyperlinks or cell templates. They determine the typeface of the cell data
|
|
Attributes
Child elemenents
Facets
|
<e:workbook>
<e:worksheet>
<e:column value="#{personList}" var="person">
<e:cell value="#{person.age">
<e:font fontName="Times New Roman" color="red" bold="true"/>
</e:cell>
</e:column>
</e:worksheet>
</e:workbook>
defines a cell with a red, bold, Times New Roman font.
Backgrounds are nested inside cells, formulas, hyperlinks or cell templates. They determine the color and pattern of the cell.
|
|
Attributes
Child elemenents
Facets
|
<e:workbook>
<e:worksheet>
<e:column value="#{personList}" var="person">
<e:cell value="#{person.age">
<e:background color="green" pattern="grey_25"/>
</e:cell>
</e:column>
</e:worksheet>
</e:workbook>
defined a green cell background with a 25% grey mask.
Borders are nested inside cells, formulas, hyperlinks and cell templates. They determine the color and line style of the cell borders.
|
|
Attributes
Child elemenents
Facets
|
<e:workbook>
<e:worksheet>
<e:column value="#{personList}" var="person">
<e:cell value="#{person.age">
<e:border border="left" color="green" lineStyle="thin"/>
</e:cell>
</e:column>
</e:worksheet>
</e:workbook>
defined a thin green border on the left edge of the cell.
Validations are nested inside cells, formulas or cell templates. They add constrains for the cell data.
|
|
Attributes
Child elemenents
Facets
|
<e:workbook>
<e:worksheet>
<e:column value="#{personList}" var="person">
<e:cell value="#{person.age">
<e:numericValidation condition="between" value="4"
value2="18"/>
</e:cell>
</e:column>
</e:worksheet>
</e:workbook>
adds numeric validation to a cell specifying that the value must be between 4 and 18.
|
|
Attributes
Child elemenents
Facets
|
<e:workbook>
<e:worksheet>
<e:column value="#{personList}" var="person">
<e:cell value="#{person.position">
<e:rangeValidation startColumn="0" startRow="0"
endColumn="0" endRow="10"/>
</e:cell>
</e:column>
</e:worksheet>
</e:workbook>
adds validation to a cell specifying that the value must be in the values specified in range A1:A10.
|
|
Attributes
Child elemenents
Facets
|
e:listValidation is a just a container for holding multiple e:listValidationItem tags.
|
|
Attributes
Child elemenents
Facets
|
<e:workbook>
<e:worksheet>
<e:column value="#{personList}" var="person">
<e:cell value="#{person.position">
<e:listValidation>
<e:listValidationItem value="manager"/>
<e:listValidationItem value="employee"/>
</e:listValidation>
</e:cell>
</e:column>
</e:worksheet>
</e:workbook>
adds validation to a cell specifying that the value must be "manager" or "employee".
Format masks are defined in the mask attribute in cell templates,
cells or formulas. Note that when using templates, the
format mask must be placed in the first template
to be cascaded since the constructor hierarchy in
JExcelAPI used for copying cell formats makes
it hard to change the format mask at a later stage. There are two
types of format masks, one for numbers and one for dates
When encountering a format mask, first it is checked if it is in internal form, e.g "format1", "accounting_float" and so on (see jxl.write.NumberFormats ).
if the mask is not in the list, it is treated as a custom mask (see java.text.DecimalFormat ). e.g "0.00" and automatically converted to the closest match.
When encountering a format mask, first it is checked if it is in internal form, e.g "format1", "format2" and so on (see jxl.write.DecimalFormats ).
if the mask is not in the list, it is treated as a custom mask (see java.text.DateFormat )., e.g "dd.MM.yyyy" and automatically converted to the closest match.
Formulas are nested within columns (for iteration) or inside worksheets
(for direct placement using the column and
row attributes) and add calculations or functions to
ranges of cells. They are essentially cells, see
Section 19.6, “Cells” for available attributes. Note that they
can apply templates and have own font definitions etc just as normal
cells.
The formula of the cell in placed in the value
-attribute as a normal the Microsoft® Excel® spreadsheet application notation. Note that when doing
cross-sheet formulas, the worksheets must exist before referencing
a formula against them. The value is a string.
<e:workbook>
<e:cellTemplate name="fooTemplate">
<e:font color="red"/>
</e:cellTemplate>
<e:worksheet name="fooSheet">
<e:cell column="0" row="0" value="1"/>
</e:worksheet>