我如何在JasperFillManager.fillReport中具有多个JRBeanCollectionDataSource? [英] How can I have multiple JRBeanCollectionDataSource in JasperFillManager.fillReport?

查看:727
本文介绍了我如何在JasperFillManager.fillReport中具有多个JRBeanCollectionDataSource?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序(带有JSP的Java应用程序)中使用Jasper Report generation. 我有一个带表的JSP页面,并且能够通过jasper报告用该数据成功生成一个.xslx文件.

I'm using Jasper Report generation in my application (Java application with JSP). I have a JSP page with a table and I was able to successfully generate a .xslx file with that data through jasper reports.

我在代码的下面几行使用了

I used below lines in the code,

dataListBeansArrayList,表中的一行是一个人的信息.因此,我们可以为此创建一个Bean,所有行的数据均为ArrayList of Person Beans,即ArrayList<Person> personalData = new ArrayList<Person>();

dataList is a ArrayList of Beans one row in the table is one persons information. So we can create a Bean for that and all row's data will be an ArrayList of Person Beans i.e. ArrayList<Person> personalData = new ArrayList<Person>();

JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(this.dataList);

JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, beanColDataSource);

因此,当它是一个表时,就这样直接进行.我有多个表,我想创建一个报告来打印这些表吗?

So when it is one table It's straight forward in that way. How about I have multiple tables and I want to create a Report to print those ?

与图片中的表一样,这些表是彼此完全独立的.

As in the image those tables are completely independent from each other.

所以现在我有多个ArrayList(数据源)

so now I have multiple ArrayLists (data sources)

ArrayList<Person> personalData =  new ArrayList<Person>();
ArrayList<Vehicle> vehicleData =  new ArrayList<Vehicle>();
ArrayList<Problem> problemData =  new ArrayList<Problem>();

但是我只能使用一个JRBeanCollectionDataSource,如下面的代码所示

But I can only use one JRBeanCollectionDataSource as in the below code

JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(this.dataList);

JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, beanColDataSource);

那我怎样才能成功地用我拥有的所有数据表制作报告?

So how can I successfully make the report with all the data tables I have ?

推荐答案

您可以构造许多子报表,并在其中使用JasperReportDataSource填充每个子报表.因此,您可以使用$F{data.personal}$F{data.vehicle}$F{data.problem}作为每个子报表的引用.

You can construct a number of subreports, where you populate each subreport using JasperReportDataSource. So you might use $F{data.personal}, $F{data.vehicle} and $F{data.problem} as references for each subreport.

每个人都将返回一个新数据源,供子报表中使用.

Each will return a new data source for use within the subreport.

这篇关于我如何在JasperFillManager.fillReport中具有多个JRBeanCollectionDataSource?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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