如何从jasper报告导出到excel中的多个工作表 [英] How to export to multiple sheets in excel from jasper report

查看:1417
本文介绍了如何从jasper报告导出到excel中的多个工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一份包含许多子报告的iReport报告。

I am working on a report with iReport that have many subreports.

我希望从我的应用程序生成报告时,excel文件中还有两张其他工作表。

I want to have two other sheets in the excel file when generating the report from my application.

在网上搜索时,我找到了关于在报告中创建中断的答案,在子报告true中有忽略分页选项,但仍然不清楚对我来说。

When searching the internet I found answers about creating a break in the report, having the option "Ignore pagination " in the subreports "true" , but it is still not clear for me.

我有什么选择来控制创建新工作表的方式和时间

What are my options to control how and when a new sheet is created

推荐答案

在jasper报告中,有不同的方法可以在 jrxml java 中实现新工作表码。默认行为是为每个页面创建一个新工作表。我将说明使用它们时相对问题的3种最常见的方法。

In jasper report there are different ways to achieve new sheet both in jrxml and in java code. The default behavior is to create a new sheet for every page. I will illustrated the 3 most common ways with relative problem in using them.


忽略分页和中断元素

方法

设置 isIgnorePagination =true jasperReport 标签上添加

<break>
  <reportElement x="0" y="0" width="100" height="1" uuid="c5371aa4-2eb4-4ab9-8cae-39f50da3317b"/>
</break>

当您需要新工作表时。

问题:如果您也导出为pdf(因为它忽略了分页),报告也不会很漂亮

Problem: The report will not be beautiful if you export also to pdf (since its ignoring pagination)


使用jrxml属性

方法
避免创建新的每个新页面上的工作表,设置属性

Method To avoid creating new sheet on every new page, set property

net.sf.jasperreports.export.xls.one.page.per.sheet="false"

当您希望它在<$ c $之前或之后创建新工作表c> reportElement 添加相对属性:

And when you want it to create a new sheet before or after an reportElement add relative property:

net.sf.jasperreports.export.xls.break.before.row="true"
net.sf.jasperreports.export.xls.break.after.row="true"

问题:每张工作表上的列都是相同的,这可能导致不同工作表上的丑陋colspan

Problem: The columns on every sheet will be the same and this can result in ugly colspan on different sheet's

使用java和c根据需要控制工作表(加载不同的报告)

方法

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

问题:你不能如果您使用的是jasper报表服务器,请使用此方法。

Problem: You can not use this method if you are using jasper report server.

这篇关于如何从jasper报告导出到excel中的多个工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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