问题描述
我在将报告导出为 XLS 时遇到了一些麻烦.导出为PDF效果很好.
I have some troubles to export my report as XLS. The export as PDF works well.
所以我尝试更新到最新的 JasperReports 和 Apache POI 版本:
So I tried to update to the latest JasperReports and Apache POI version:
- JasperReports:5.5.0
- 兴趣点:3.7
- iText:2.1.7
但是我总是收到以下异常消息:
But I receive always following exception:
java.lang.NoSuchMethodError: org.apache.poi.hssf.usermodel.HSSFWorkbook.createDataFormat()Lorg/apache/poi/hssf/usermodel/HSSFDataFormat;
net.sf.jasperreports.engine.export.JRXlsExporter.openWorkbook(JRXlsExporter.java:284)
net.sf.jasperreports.engine.export.JRXlsAbstractExporter.exportReportToStream(JRXlsAbstractExporter.java:927)
net.sf.jasperreports.engine.export.JRXlsAbstractExporter.exportReport(JRXlsAbstractExporter.java:697)
com.phoenix.customermonitor.print.GenericDataSourceApp.xls(GenericDataSourceApp.java:290)
com.phoenix.customermonitor.print.GenericDataSourceApp.exportToFormat(GenericDataSourceApp.java:335)
com.phoenix.core.JasperReportHandlerAction.exportOrderMonitorOverview(JasperReportHandlerAction.java:242)
com.phoenix.customermonitor.action.OrderMonitorMainAction.execute(OrderMonitorMainAction.java:217)
org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
javax.servlet.http.HttpServlet.service(HttpServlet.java:643)
javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
导出代码
File sourceFile = new File(fileIn);
JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile);
String name = fileIn.substring(fileIn.lastIndexOf(System.getProperty("file.separator"))+1);
name = name.substring(0, name.lastIndexOf("."));
File destFile = new File(fileOut);
JRXlsExporter exporter = new JRXlsExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString());
exporter.exportReport();
经过一些研究,我尝试了其他多个版本(+4),但仍然收到此错误.有人知道解决方案吗?
After some researches I tried several other Versions(+4) but I still receive this error. Does anyone know a solution?
推荐答案
您的类路径中有旧版本库.
You have an old version library in your class path.
如果碧玉报告依赖于lib-xxx.jar,则请确保您的类路径中没有其他lib-yyy.jar.您可以通过查看jasper下载的jar或pom.xm来做到这一点.
If the jasper report depends on lib-xxx.jar, then make sure that there are no other lib-yyy.jar in your class path. You can do this by reviewing the jasper downloaded jar or pom.xm.
据我猜测,您的课程路径中有一些旧版本的poi.
As I can guess there are some old versions of poi in your class path.
这篇关于java.lang.NoSuchMethodError:org.apache.poi.hssf.usermodel.HSSFWorkbook.createDataFormat()Lorg/apache/poi/hssf/usermodel/HSSFDataFormat;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!