这个问题已经被问过一次,但没有人给出绝对的解决方案。我试图从现有模板生成一个 xls 文件,但我得到一个我不知道如何面对的错误!
我的代码: 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();
}
这正在被实现到 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
非常感谢!