Java JasperReports 5.6:JRXlsExporter.setParameter已被弃用

Java JasperReports 5.6:JRXlsExporter.setParameter已被弃用,java,jasper-reports,export,deprecated,Java,Jasper Reports,Export,Deprecated,我有以下代码可以将JasperReprot导出到XLS: JasperPrint jprint=JasperFillManager.fillReport(expRpg, null, new JRBeanCollectionDataSource(datalist)); JRXlsExporter exporter = new JRXlsExporter(); exporter.setParameter(JRXlsExporterParameter.J

我有以下代码可以将JasperReprot导出到XLS:

        JasperPrint jprint=JasperFillManager.fillReport(expRpg, null, new JRBeanCollectionDataSource(datalist));
        JRXlsExporter exporter = new JRXlsExporter();
        exporter.setParameter(JRXlsExporterParameter.JASPER_PRINT, jprint); 
        exporter.setParameter(JRXlsExporterParameter.OUTPUT_STREAM, outStream);
        exporter.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE); 
        exporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
        exporter.exportReport();
升级到JasperReports 5.6时,所有setParameter都被标记为“已弃用”,我找不到修改此代码的文档


如何使用JasperReports 5.6将报表导出到xls?

JRExporter在5.6中遭到了弃用。他们引入了新的接口导出器,并对所有导出器进行了改造,使其具有ExporterInput、ReportExportConfiguration、ExporterConfiguration和ExporterOutput。请参阅下面的链接

这意味着,您需要使用上述类或其子类来创建配置,而不是setParameter PDF导出示例。Excel导出应遵循相同的方法

JRPdfExporter exporter = new JRPdfExporter();

exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
exporter.setExporterOutput(outputStream);
SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
exporter.setConfiguration(configuration);

exporter.exportReport();
卓越对手

JRXlsExporter exporter = new JRXlsExporter();
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(destFile));
SimpleXlsReportConfiguration configuration = new SimpleXlsReportConfiguration();
configuration.setOnePagePerSheet(true);
configuration.setDetectCellType(true);
configuration.setCollapseRowSpan(false);
exporter.setConfiguration(configuration);

exporter.exportReport();

SimpleXlsReportConfiguration将具有与excel导出相关的配置。根据您的要求设置值

感谢以上代码,以下是我的代码: 注意:使用ireport、ireport 6.0、java 7导出excel

 Map<String, Object> parametro = new HashMap<String, Object>();
                parametro.put("USUARIO", UConstante.NAME_MINISTERIO_USER);
                parametro.put("RUTA_LOGO", PuenteFile.getRutaFiles(FacesContext.getCurrentInstance(), PuenteFile.RUTA_IMG_LOGO));
                parametro.put("PATH_SYSTEM", rutaFileSystemHD);
                parametro.put("WHERE_DATA", WHERE_REGISTRO);
                parametro.put("WHERE_PROYECTO_USUARIO", WHERE_PROYECTO_USUARIO);
                parametro.put("WHERE_ZONA", WHERE_ZONA);
                parametro.put("NAME_APP", RutaFile.NAME_APP);
                parametro.put("ID_USUARIO", getUsuario().getId());
                parametro.put("ID_PROYECTO", beanProyecto.getId());
                parametro.put("SUBREPORT_DIR", SUBREPORT_DIR);

                System.out.println(">>>>>> PARAMETROS :" + parametro.toString());

              try {
                    JasperPrint jasperPrint = JasperFillManager.fillReport(path, parametro, PgConnector.getConexion());
                    JRXlsExporter xlsExporter = new JRXlsExporter();
                    xlsExporter.setExporterInput(new SimpleExporterInput(jasperPrint));
                    xlsExporter.setExporterOutput(new SimpleOutputStreamExporterOutput(PuenteFile.getRutaFiles(FacesContext.getCurrentInstance(), PuenteFile.RUTA_REPORT_FILE) + nameExcel));
                    SimpleXlsReportConfiguration xlsReportConfiguration = new SimpleXlsReportConfiguration();
                    SimpleXlsExporterConfiguration xlsExporterConfiguration = new SimpleXlsExporterConfiguration();
                    xlsReportConfiguration.setOnePagePerSheet(true);
                    xlsReportConfiguration.setRemoveEmptySpaceBetweenRows(false);
                    xlsReportConfiguration.setDetectCellType(true);
                    xlsReportConfiguration.setWhitePageBackground(false);
                    xlsExporter.setConfiguration(xlsReportConfiguration);
                    xlsExporter.exportReport();

                } catch (Exception ex) {
                    ex.printStackTrace();
                }
Map parametro=newhashmap();
参数put(“USUARIO”,UConstante.NAME\u MINISTERIO\u USER);
parametro.put(“RUTA_LOGO”,PuenteFile.getRutaFiles(FacesContext.getCurrentInstance(),PuenteFile.RUTA_IMG_LOGO));
参数put(“路径系统”,rutaFileSystemHD);
参数put(“WHERE\u DATA”,WHERE\u REGISTRO);
参数put(“WHERE_PROYECTO_USUARIO”,WHERE_PROYECTO_USUARIO);
参数put(“WHERE_ZONA”,WHERE_ZONA);
参数put(“名称应用程序”,金红石。名称应用程序);
参数put(“ID_USUARIO”,getUsuario().getId());
parametro.put(“ID_PROYECTO”,beanProyecto.getId());
参数put(“子报告目录”,子报告目录);
System.out.println(“>>>>PARAMETROS:”+parametro.toString());
试一试{
JasperPrint-JasperPrint=JasperFillManager.fillReport(路径、参数、PgConnector.getConexion());
JRXlsExporter xlsExporter=新的JRXlsExporter();
xlsExporter.setExporterInput(新的SimpleExporterInput(jasperPrint));
xlsExporter.setExporterOutput(新的SimpleOutputStreamExporterOutput(PuenteFile.getRutaFiles(FacesContext.getCurrentInstance(),PuenteFile.RUTA_报告_文件)+nameExcel));
SimpleXlsReportConfiguration xlsReportConfiguration=新SimpleXlsReportConfiguration();
SimplexlExporterConfiguration xlsExporterConfiguration=新SimplexlExporterConfiguration();
xlsReportConfiguration.setOnePagePerSheet(true);
xlsReportConfiguration.setRemoveEmptySpaceBetweenRows(false);
xlsReportConfiguration.setDetectCellType(true);
xlsReportConfiguration.setWhitePageBackground(false);
xlsExporter.setConfiguration(xlsReportConfiguration);
xlsExporter.exportReport();
}捕获(例外情况除外){
例如printStackTrace();
}
这是我的代码:

String sourceFileName = "./jasper_report_template.jasper";
Map parameters = new HashMap();
String printFileName = null;
try {
      printFileName = JasperFillManager.fillReportToFile(sourceFileName, parameters, beanArrayDataSource);
      if(printFileName != null){
           //JasperPrintManager.printReport( printFileName, true);
            /** 1- export to PDF*/
            JasperExportManager.exportReportToPdfFile(printFileName,
                      "C://Users/zanderkong/Desktop/sample_report.pdf");
            /**3- export to Excel sheet*/
            RXlsExporter xlsExporter = new JRXlsExporter();
            xlsExporter.setExporterInput(new SimpleExporterInput(printFileName));
            xlsExporter.setExporterOutput(new SimpleOutputStreamExporterOutput("C://Users/zanderkong/Desktop/sample_report.xls"));
            SimpleXlsReportConfiguration configuration = new SimpleXlsReportConfiguration();
            configuration.setOnePagePerSheet(true);
            configuration.setDetectCellType(true);
            configuration.setCollapseRowSpan(false);
            xlsExporter.setConfiguration(configuration);
            xlsExporter.exportReport();
         }
        } catch (JRException e) {
             e.printStackTrace();
          }      

您应该阅读:
替换为setExporterInput(ExporterInput)、setConfiguration(ExporterConfiguration)、setConfiguration(ReportExportConfiguration)和setExporterOutput(ExporterOutput)
,如果您使用的是类似于
ByteArrayOutputStream
的类,则应该执行以下操作:
exporter.setExporterOutput(新的SimpleOutputStreamExportRoutPut(os))excel counterpartFor
xlsx
(与
xls
)报告中缺少一行“exporter.exportReport();”,相应的配置类为
SimpleXlsxReportConfiguration