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

6

7

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!

Inanimate answered 10/3, 2016 at 16:24 Comment(0)
F
2

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

Furred answered 10/3, 2016 at 20:50 Comment(7)
Yes I have installed all the needed files, do you think that it might have to do with the template file location?Inanimate
No, I do not think it is related to template location. Can you also post the full error stack trace?Furred
Solved. It had to do with the maven dependecies installation.Inanimate
I added and extra dependencies making it overcollapse. Thanks anywaysInanimate
@LorenzoGamboa what were the extra dependencies? Could you show a pom file?Cyrenaica
I'm not the OP but the answer provided the correct hint: I needed to install Apache POI (quite obvious, actually). ThanksZsa
I have added the jxls-poi-1.0.12.jar file in the lib folder, which is the apache-poi file, isn't it? Or I still need to add other files?Coimbra
L
2

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.

Loblolly answered 29/6, 2018 at 8:6 Comment(0)
S
0

ok,if you use maven ,when maven build , maven could broken excel file.

Exceptions reported by JXLS can be ambiguous,it's actually creating a excel file exception.

you can do like this:

<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>
Sendal answered 6/9, 2017 at 7:33 Comment(0)
P
0

I also encountered the same issue when using maven profiles and resource filtering. It was fixed by turning off the resource filtering to your jxls excel templates.

  <resource>
    <directory>src/main/resources/</directory>
    <filtering>false</filtering>
    <includes>
      <include>**/*.xlsx</include>
    </includes>
  </resource> 
Plenteous answered 15/11, 2017 at 10:37 Comment(0)
P
0

Make sure jxls and jxls-poi are in your maven pom, Also check your template file is in your class path or not.

I encountered this problem, my code like :

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

My problem is I mistyped /template.xlsx as /template.xls, jxls cannot find the template xls file, so this error thrown.

Purple answered 3/3, 2018 at 14:49 Comment(0)
F
0

It is strange that throughout the entire Internet there is still no answer to this question. First of all, you just need to replace ExportExcelServlet.class.getResourceAsStream with FileInputStream

Faithfaithful answered 13/7, 2019 at 12:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.