我正在使用iReport处理包含许多子报表的报表。
从我的应用程序生成报告时,我想在excel文件中另放两张纸。
在互联网上搜索时,我发现了有关在报表中创建中断的答案,在子报表“ true”中具有选项“忽略分页”,但对我来说仍然不清楚。
我有哪些选择来控制创建新工作表的方式和时间
在jasper report中,有多种方法可以jrxml在java代码中和代码中实现新工作表。默认行为是为每个页面创建一个新工作表。我将说明3种最常见的使用方式中存在相对问题的方式。
忽略分页和中断元素
方法
isIgnorePagination="true"在jasperReport标签上设置并添加
<break>
<reportElement x="0" y="0" width="100" height="1" uuid="c5371aa4-2eb4-4ab9-8cae-39f50da3317b"/>
</break>
Run Code Online (Sandbox Code Playgroud)
当您需要一张新纸时。
问题:如果您还导出为pdf,报告将不会很漂亮(因为它忽略了分页)
使用jrxml属性
方法 为了避免在每个新页面上创建新工作表,请设置属性
net.sf.jasperreports.export.xls.one.page.per.sheet="false"
Run Code Online (Sandbox Code Playgroud)
当您希望它在reportElement添加相对属性之前或之后创建一个新工作表时:
net.sf.jasperreports.export.xls.break.before.row="true"
net.sf.jasperreports.export.xls.break.after.row="true"
Run Code Online (Sandbox Code Playgroud)
问题:每张纸上的列都相同,这可能导致不同纸上的列错
使用Java并根据需要控制工作表(加载不同的报告)
方法
List<JasperPrint> sheets = new ArrayList<JasperPrint>();
for (int i=1;i<=8;i++){
JasperPrint print = JasperFillManager.fillReport("subReport_" + i + ".jasper", paramMap, connection);
sheets.add(print);
}
JRXlsxExporter exporter = new JRXlsxExporter();
exporter.setExporterInput(SimpleExporterInput.getInstance(sheets));
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(new File("text.xlxs"));
SimpleXlsxReportConfiguration configuration = new SimpleXlsxReportConfiguration();
configuration.setSheetNames(sheetNames): //sheets names is an array of the different names.
configuration.setOnePagePerSheet(false); //remove that it break on new page
configuration.setDetectCellType(true);
exporter.setConfiguration(configuration);
exporter.exportReport();
Run Code Online (Sandbox Code Playgroud)
问题:如果您使用的是jasper报表服务器,则不能使用此方法。
| 归档时间: |
|
| 查看次数: |
8797 次 |
| 最近记录: |