Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jxls Error : Cannot load XLS transformer. Please make sure a Transformer implementation is in classpath

Tags:

java

excel

jxl

jxls

This question has been already asked once but no one gave a absolute solution to it. Im trying to generate a xls file from a existing template but im getting an error which I dont know how to face out!

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 being implemented into a 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 alot!

like image 392
Lorenzo Gamboa Avatar asked Mar 10 '16 16:03

Lorenzo Gamboa


2 Answers

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

like image 89
Leonid Vysochyn Avatar answered Oct 23 '22 16:10

Leonid Vysochyn


In my case, I have incompatible apache poi versions in my classpath. jxls-poi:1.0.15 uses poi:3.17, while I have poi:3.9.

Changing poi to 3.17 fixed my issue.

like image 42
xick Avatar answered Oct 23 '22 16:10

xick