Jasper Report导出到xls 5.6版

时间:2014-08-01 13:31:04

标签: java jasper-reports

运行代码后,它可以在else块中正常使用PDF ...但 xls 完全失效。堆栈跟踪我试图弄清楚问题,我只是空白。

        Exporter exporter = null;            
        ...
        ...
        ... omitted various: template compile, load, etc, and case statement, to switch to correct exporter

         case "xls":
                exporter = new JRXlsExporter();
                break;

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        bos = new BufferedOutputStream(baos);

        if (reportType.equals("xls"))
        {
            exporter.setExporterInput(new SimpleExporterInput(jprint));
            exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(baos));
            SimpleXlsReportConfiguration configuration = new SimpleXlsReportConfiguration();
            configuration.setOnePagePerSheet(false);
            configuration.setDetectCellType(true);
            configuration.setCollapseRowSpan(false);
            configuration.setWhitePageBackground(false);
            configuration.setRemoveEmptySpaceBetweenRows(true);
            exporter.setConfiguration(configuration);
        }
        else
        {
            exporter.setExporterInput(new SimpleExporterInput(jprint));
            exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(baos));
        }
        exporter.exportReport();

尝试使用XLS时的堆栈跟踪如下

Caused by: java.lang.reflect.UndeclaredThrowableException
at com.sun.proxy.$Proxy18.isForceLineBreakPolicy(Unknown Source)
at net.sf.jasperreports.engine.export.JRPdfExporter.initReport(JRPdfExporter.java:547)
at net.sf.jasperreports.engine.JRAbstractExporter.setCurrentExporterInputItem(JRAbstractExporter.java:567)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportReportToStream(JRPdfExporter.java:735)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportReport(JRPdfExporter.java:513)
at com.com.com.reporting.ReportManager.generateReport(ReportManager.java:120)
... 6 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at net.sf.jasperreports.export.CompositeExporterConfigurationFactory$DelegateInvocationHandler.invoke(CompositeExporterConfigurationFactory.java:159)
... 12 more
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at net.sf.jasperreports.export.CompositeExporterConfigurationFactory$DelegateInvocationHandler.invoke(CompositeExporterConfigurationFactory.java:159)
at com.sun.proxy.$Proxy18.isForceLineBreakPolicy(Unknown Source)
... 17 more

输出的文件完全是胡说八道,但是,将扩展名从“.xls”更改为“.pdf”,它可以作为PDF。对于我现在不确定的事情,有些事情是完全错误的。

3 个答案:

答案 0 :(得分:0)

你能否确认无效代码是正确的,你确实有JRXlsExporter的实例?如果JRPdfExporter提供了SimpleXlsReportConfiguration,我会期待这样的堆栈跟踪。

答案 1 :(得分:0)

好的......所以结果是:

Exporter exporter = null;   
exporter = new JRXlsExporter();  

这不起作用,而不是使用父类来调用必须显式使用每个单独类型的每种不同报告类型。我没有必要改变除此之外的任何东西

显然正在使用的其他报告从原来的问题中删除):

JRXlsxExporter jrXlsxExporter = new JRXlsxExporter();

答案 2 :(得分:0)

就我而言,我升级了POI,因此它破坏了动态报告 所以解决方案降级了POI,因为我找不到合适的 它的版本与动态报告兼容。我有两个选择 降级poi或升级动态报告,我选择降级poi

enter image description here

enter image description here

enter image description here