Search code examples
apache-poijxls

How can I figure out which version of apache POI is needed for jXLS 2.3.0?


This is my Gradle file:

compile 'org.apache.poi:poi:3.13'
compile 'org.jxls:jxls-jexcel:1.0.6'
compile 'org.jxls:jxls-poi:1.0.9'
compile 'org.jxls:jxls:2.3.0'

It looks like I'm using the wrong version of apache POI:

java.lang.NoSuchMethodError: org.apache.poi.ss.usermodel.Workbook.getCellStyleAt(S)Lorg/apache/poi/ss/usermodel/CellStyle;
at org.jxls.transform.poi.PoiTransformer.clearCell(PoiTransformer.java:224)
at org.jxls.area.XlsArea.clearCells(XlsArea.java:437)
at org.jxls.builder.xls.XlsCommentAreaBuilder.build(XlsCommentAreaBuilder.java:181)
at org.jxls.template.SimpleExporter.gridExport(SimpleExporter.java:54)

Isn't it a bit strange that I have to explicitly include a dependency that another dependency depends upon? Moreover, how can I figure out which version of the dependency (the POI) I actually need?

I am just trying to get the simple exporter sample to work:

   try (InputStream is = CalXlsExporter.class.getResourceAsStream(template)) {
        try (OutputStream os2 = new FileOutputStream("ExportOutput.xlsx")) {

            headers = Arrays.asList(HEADERS);

            Context context = new Context();
            context.putVar("headers", HEADERS);
            context.putVar("cell", cal);

            JxlsHelper.getInstance().processTemplate(is, os2, context); //Exception inside this
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

Solution

  • You can always look at the Maven pom file of jxls-poi module for example you can see that jxls-poi-1.0.9 contains a dependency to POI 3.12 as defined in pom properties section

    <properties>
      ...
      <poi.version>3.12</poi.version>
      ...  
    </properties>
    

    It may happen that later POI versions can also work but it is not always the case because it depends on Apache POI backwards compatibility.