Jxls error: unable to load XLS transformer. Make sure the Transformer implementation is in the classpath

This question has already been asked once, but no one has given him an absolute solution. Im trying to generate an xls file from an existing template, but im getting an error that I don't know how to resist!

My code: String nombre = "Manuel";

        try (InputStream templateFileName = ExportExcelServlet.class.getResourceAsStream("/segJBOSS/lib/xls/Tabla_Gestion.xlsx")) {
            try (OutputStream destFileName = new FileOutputStream("Tabla_Gestion.xls")) {
                ArrayList<String> array = new ArrayList<String>();
                array.add(nombre);
                Context context = new Context();
                context.putVar("gestion", array);
                JxlsHelper.getInstance().processTemplate(templateFileName, destFileName, context);              
                } catch (Exception e) {
                // TODO: handle exception
                System.out.println(e.getMessage());
                e.printStackTrace();                
                }

        } catch (Exception e) {
            // TODO: handle exception
            System.out.println(e.getMessage());
            e.printStackTrace();
        }
    } catch (Exception e) {
        // TODO: handle exception
        System.out.println(e.getMessage());
        e.printStackTrace();
    }

This is embedded in the WebServlet.

17:08:43,472 ERROR [org.jxls.util.TransformerFactory] (default task-3) Method createTransformer of org.jxls.transform.poi.PoiTransformer class thrown an Exception: java.lang.reflect.InvocationTargetException

Caused by: java.lang.NullPointerException

17:08:43,478 INFO  [stdout] (default task-3) Cannot load XLS transformer. Please make sure a Transformer implementation is in classpath
17:08:43,479 ERROR [stderr] (default task-3) java.lang.IllegalStateException: Cannot load XLS transformer. Please make sure a Transformer implementation is in classpath

Thanks a lot!

+6
source share
6 answers

Please make sure you have jxls-poi and Apache POI jars in the classpath (if you plan to use Apache POI)

+1
source

maven . , jxls excel.

  <resource>
    <directory>src/main/resources/</directory>
    <filtering>false</filtering>
    <includes>
      <include>**/*.xlsx</include>
    </includes>
  </resource> 
+1

ok, maven, maven build, maven excel.

, JXLS, , excel .

:

<resources>
        <resource>
            <directory>src/main/resources/</directory>
            <filtering>true</filtering>
            <excludes>
                <exclude>template/*.*</exclude>
            </excludes>
        </resource>
        <resource>
            <directory>src/main/resources/</directory>
            <filtering>false</filtering>
            <includes>
                <include>template/*.*</include>
            </includes>
        </resource>
 </resources>
0

, jxls jxls-poi maven mom, , .

, :

InputStream is = JxlsTest.class.getResourceAsStream("/template.xlsx");

, /template.xlsx /template.xls, jxls xls, .

0

apache poi classpath. jxls-poi:1.0.15 poi:3.17, poi:3.9.

Changing poi to 3.17 fixed my problem.

0
source

It is strange that there is still no answer to this question all over the Internet. First of all, you just need to replace ExportExcelServlet.class.getResourceAsStreamwithFileInputStream

0
source

All Articles