Java2Excel 1.3.1 review
DownloadJava2Excel is a library that allows the generation of simple excel files using objects of type java.util.Collection. The current v
|
|
Java2Excel is a library that allows the generation of simple excel files using objects of type java.util.Collection.
The current verison of Java2Excel contains a lot of limitations. You can only write the collection in excel files using an xml file as a descriptor of what properties you want in the excel file. In the current state, there is not much error checking.
Example
The following is an example of an xml file used to configure the output to excel.
Please, note that this is a preliminary version and this file may not be compatible with future versions
< ?xml version="1.0" encoding="ISO-8859-1"?>
< !DOCTYPE java2excel PUBLIC
"-//epere4/DTD Java2Excel mapping file//EN"
"http://java2excel.sourceforge.net/dtd/java2excel-mapping.dtd">
< java2excel>
< header>
nothing for now
< /header>
< body>
< properties>
< property name="text">
< description>
This is a text property.
< /description>
< /property>
< property name="integerNumber" />
< property name="date" />
< property name="calendar" />
< property name="boolValue" />
< property name="internal.integerNumber" />
< /properties>
< /body>
< /java2excel>
The name attributes are ognl expressions that are applied to each element in the collection.
For example, integerNumber will be traduced to something like elementInCollection.getIntegerNumber() (with elementInCollection being the name of the variable for each element in the collection, of course). A more complex expresion like internal.integerNumber is equivalent to elementInCollection.getInternal().getIntegerNumber() (watch for NullPointerExceptions, here; there will be some protection for this in future releases)
The following is the code used in ar.com.epere4.java2excel.excelWritter.ExcelWritterTest .
The getMockCollection(5) method, not shown here, will just generate a java.util.Collection with 5 elements that will have all the properties requested by the XML file previously shown.
Parser parser = new Parser();
Java2ExcelDtd java2ExcelDtd = parser.parse(this.getClass()
.getResourceAsStream("/ar/com/epere4/java2excel/excelWritter/ExcelWritterTest.xml"));
ExcelWritter excelWritter = new ExcelWritter();
excelWritter.addReport(getMockCollection(5), java2ExcelDtd);
excelWritter.saveTo(new File("anExcel.xls"));
What's New in This Release:
The "Too many different cell formats" error message in Excel was fixed.
An id was added for properties.
If not specified, it will continue to be the expression, as before.
The setIncludeExtraLevel method was added to the BodyDtd interface.
Maven 2.0 is now used.
Maven 1.0 support should be considered deprecated.
It will be maintained only for code dependencies, but the site will be generated using Maven 2.0 from now on.
Java2Excel 1.3.1 keywords