如何在Jasper Reports中动态添加多个数据 [英] How to dynamically add multiple pieces of data in Jasper Reports

查看:1073
本文介绍了如何在Jasper Reports中动态添加多个数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个贾斯珀报告,我正在使用Java。

I have a Jasper Report I am working on in Java.

在Java中,我可以使用以下代码动态填充带有数据的bean:

In Java I can dynamically populate a bean with data with the following code:

    List<ThemeBean> themes = new ArrayList<ThemeBean>();
    CSVReader csvReader = new CSVReader(new FileReader(csvFilename));
    List<String[]> data = csvReader.readAll();
    for(String[] d : data) {
        ThemeBean tb = new ThemeBean();
        tb.setThemes(d[0]);
        tb.setComments(d[1]);
        tb.setSentiment(d[2]);
        themes.add(tb);
    }   
        JasperDesign jasperDesign = JRXmlLoader.load(fileName);
        JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(themes);
        JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
        JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, ds);

当.jrxml文件在标签中指定了正确的字段和textFieldExpression时,这种方法很有效...

This works well when the .jrxml file has the correct fields specified and textFieldExpression within the tags...

以下内容通过构建的List动态填充:

The following gets dynamically populated with the List that was built:

<textFieldExpression><![CDATA[$F{themes}]]></textFieldExpression>

我的问题是如何动态地为同一报告中的两个不同的表执行此操作。似乎我只能用于动态添加一次迭代的数据。我试图实现一个结果,我在同一个报告中生成了两个完全不同的表。如果这个问题不明确,请告诉我,我会尝试修复它。谢谢。

My problem is figuring out how to do this Dynamically for two different tables in the same report. It seems that I can only use for one iteration of data to be dynamically added. I am trying to achieve a result where I have two completely different tables generated within the same report. If this question isn't clear, please let me know and I will attempt to fix it. Thanks.

推荐答案

Jasper ideology:一个报告 - 一个DataSource。

Jasper ideology: one report - one DataSource.

在主报表中使用2子报表。 Main.jrxml包含subreport1(用于显示列表)和subreport2(用于List)。 Subreport1和Subreport2放入标题(或摘要)区域。

Use 2 subreport in main report. Main.jrxml contains subreport1 (for display List) and subreport2 (for List). Subreport1 and Subreport2 put into Title (or Summary) band.

在Main.jrxml中定义参数:themesPar,anotherPar as java.util.Collection

Define parameters in Main.jrxml : themesPar, anotherPar as java.util.Collection

这篇关于如何在Jasper Reports中动态添加多个数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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