Jasper Report导出到xls 5.6版

问题描述 投票:0回答:3

运行代码后,它可以在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。关于我现在不确定的事情,有些事情是完全错误的。

java jasper-reports
3个回答
0
投票

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


0
投票

好的...所以事实证明:

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

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

(显然,对于我原来的问题中省略的其他报告):

JRXlsxExporter jrXlsxExporter = new JRXlsxExporter();

0
投票

在我的情况下,我升级了POI,因此它破坏了动态报告,因此解决方案降级了POI,因为我找不到与动态报告兼容的正确版本。我有两个选择要么降级poi要么升级动态报告我选择降级poi

enter image description here

enter image description here

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.