JasperReports中每张工作表一页 [英] One page per sheet property in JasperReports

查看:247
本文介绍了JasperReports中每张工作表一页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要求,我必须在JasperReports中设计一个报告。该报告有4张。第一张纸有5页,类似地其他纸张有一页或两页。我面临的问题是如果我使用 net.sf.jasperreports.export.xls.one.page.per.sheet 属性并将其设置为 true ,然后所有页面都有不同的表格。我需要设计报告,使得某些页面将出现在同一张纸上,而某些页面则放在不同的纸张中。

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.

是否可以这样做?

推荐答案

假设您有4个单独的报告,您批量导出,那么在每个报告中您需要设置忽略分页 true (它是jrxml文件初始化时jasperReport标记中的一个属性,该属性看起来像 isIgnorePagination =true)。

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();

要设置工作表名称,请查看动态工作表名称他们在JasperForge的例子。

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



根据您的评论,您希望使用相同的报告模板导出为多种格式。 excel是唯一需要忽略分页的人。您可以做的是在运行时通过参数设置,而不是在报告中硬编码。所以将以下内容添加到params1,params2,params3和params4:


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);
}

这篇关于JasperReports中每张工作表一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆