Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

excel - One page per sheet property in JasperReports

I have a requirement where I have to design a report in JasperReports. The report has 4 sheets. The first sheet has 5 pages and similarly other sheets has one or two pages.The problem that I am facing is if I use the net.sf.jasperreports.export.xls.one.page.per.sheet property and set it to true, then all the pages comes in different sheets. I need to design the report in such a manner that some pages will come in a same sheet and some pages in a different sheet.

Is it possible to do this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Assuming you Have 4 separate reports that you are batch exporting, then in each report you need to set Ignore Pagination to true (it is an attribute in the jasperReport tag at the beggining of the jrxml file, the attribute looks like isIgnorePagination="true").

To actually export it should look similar to this:

List<JasperPrint> jasperPrintList = new ArrayList<JasperPrint>();
jasperPrintList.add(JasperFillManager.fillReport("report1.jasper", params1));
jasperPrintList.add(JasperFillManager.fillReport("report2.jasper", params2));
jasperPrintList.add(JasperFillManager.fillReport("report3.jasper", params3));
jasperPrintList.add(JasperFillManager.fillReport("report4.jasper", params4));

JRXlsExporter exporter = new JRXlsExporter();

exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, jasperPrintList);
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, "BatchExportReport.xls");
exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.TRUE);

exporter.exportReport();

To set the sheet names, take a look at Dynamic Sheet Names example they have at JasperForge.


According to your comment you are wanting to use the same report templates to export to multiple formats. With excel being the only one that needs to ignore pagination. What you can do is set via a parameter at runtime instead of hardcoded in the report. So add the following to the params1,params2,params3,and params4:
if(exportFormat == EXCEL) {
   params1.put(JRParameter.IS_IGNORE_PAGINATION, Boolean.TRUE);
   params2.put(JRParameter.IS_IGNORE_PAGINATION, Boolean.TRUE);
   params3.put(JRParameter.IS_IGNORE_PAGINATION, Boolean.TRUE);
   params4.put(JRParameter.IS_IGNORE_PAGINATION, Boolean.TRUE);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...