您可以准备一份报告列表并将其添加到 JasperPrint 列表中。
最后,您可以将列表中所有工作表的名称设置为:
exporterXLS.setParameter(JRXlsAbstractExporterParameter.SHEET_NAMES, new String[] {"sheet one", "sheet two",
"sheet three"});
其中 exporterXLS 是 JRXlsExporter 类的一个实例。
下面是我上面描述的一个更完整的例子:
Connection con = this.jdbcTemplate.getDataSource().getConnection();
Map<String, String> hashmap = new HashMap<String, String>();
hashmap.put("ReportQuery", this.ReportQuery);
JasperReport myJasperReport = JasperCompileManager.compileReport(this.reportJRXML);
JasperPrint myJasperPrint = JasperFillManager.fillReport(myJasperReport, hashmap, con);
List<JasperPrint> jprintList = new ArrayList<JasperPrint>();
jprintList.add(myJasperPrint);
OutputStream outputfile = new FileOutputStream(new File(this.outputExcel));
JRXlsExporter exporterXLS = new JRXlsExporter();
exporterXLS.setParameter(JRExporterParameter.JASPER_PRINT_LIST, jprintList);
exporterXLS.setParameter(JRExporterParameter.OUTPUT_STREAM, outputfile);
exporterXLS.setParameter(JRXlsAbstractExporterParameter.IS_COLLAPSE_ROW_SPAN, Boolean.TRUE);
exporterXLS.setParameter(JRXlsAbstractExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_COLUMNS, Boolean.TRUE);
exporterXLS.setParameter(JRXlsAbstractExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
exporterXLS.setParameter(JRXlsAbstractExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE);
exporterXLS.setParameter(JRXlsAbstractExporterParameter.IS_DETECT_CELL_TYPE, Boolean.FALSE);
exporterXLS.setParameter(JRXlsAbstractExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
exporterXLS.setParameter(JRXlsAbstractExporterParameter.IS_IGNORE_GRAPHICS, Boolean.TRUE);
exporterXLS.setParameter(JRXlsAbstractExporterParameter.SHEET_NAMES, new String[] {"first report"});
exporterXLS.exportReport();