Search code examples
javaexceljxls

How to migration JXLS from version 1 to 2


JXLS 2 is not backward compatible with version 1. There are no upgrade instructions and while I can get things working with version two I'm having two issues.

  • Version 1 did not require use of comment tags, but now I cant get the output to generate without them.

  • Java code must specify which worksheet location to write the results, in version 1, output was written on top of the template which did not require duplication of template settings in Excel and Java code.

If I cannot find a workaround to these two issues, I'll have to go change every single template to use comments. But worse, I'll also have to make my java code aware of the template worksheet layout. I dont understand why this is the default behavior. Is there any way to get version 2 to behave more like version 1?


Solution

  • Version 1 did not require use of comment tags, but now I cant get the output to generate without them.

    This is not completely true. You can choose not to use XlsCommentAreaBuilder. In this case you have 3 options

    1. Use XmlAreaBuilder (probably not the way you want)

    2. Use Java API to build the commands (probably not the way you want)

    3. Create your own Jxls1TagCommandAreaBuilder which will build the commands from the Jxls-1 tag notation (and contribute it to back to jxls core)

    The 3 option is probably the best because you will be able to use Jxls-1 templates with Jxls-2 without changes. Sure it is not trivial but should be possible.

    Java code must specify which worksheet location to write the results, in version 1, output was written on top of the template which did not require duplication of template settings in Excel and Java code.

    To get the Jxls-1 behaviour here you can just do something like this

            for (Area xlsArea : xlsAreaList) {
                xlsArea.applyAt(
                         new CellRef(xlsArea.getStartCellRef().getCellName()), context);
            }
    

    So you simply apply an area at its starting cell.

    If you wish this to be a default behavior you can raise an improvement in jxls issue tracker