如何以3个样本打印碧玉报告,几乎没有变化?

时间:2012-12-17 14:28:14

标签: java jasper-reports ireport

我用iReport创建了一个jasper报告,我可以完美地打印出来。 我需要打印3个示例(原始示例,客户端示例,部门示例),只需更改一些,例如更改报表中的标签。

我将PRINT_FOR作为参数传递给iReport。

是否有人知道如何实现这一目标?

HashMap parameters = new HashMap();
String option = "C:\\option.jasper";
JRDataSource beanDataSource = reportMapper.getDataSource();
JasperPrint jasperPrint = JasperFillManager.fillReport(option, parameters, beanDataSource);
JasperPrintManager.printPage(jasperPrint, 0, true))

3 个答案:

答案 0 :(得分:2)

首先想到的是制作一个通用报告模板,并有一些“钩子”,您可以在其中插入每个版本的差异;您可以通过Java中的参数发送“差异”。

答案 1 :(得分:2)

您可以使用Static Text代替使用Text Field字段,它允许您使用和表达式来确定文本输出。在这种情况下,您将检查PRINT_FOR参数是否等于客户端或部门,如果不使用原始值。你的表达式看起来像这样:

($P{PRINT_FOR}.equals("DEPARTMENT") ? "Department Label" : ($P{PRINT_FOR}.equals("CLIENT") ? "Client Label" : "Original Label"))

Department Label等于PRINT_FOR时输出DEPARMTNENTClient Label等于PRINT_FOR时输出Client,{如果它不等于上述任何一个,则输出{1}}。

另外值得注意的是,在代码片段中,您从未在Java代码中设置Original Label参数的值,并且您没有使用通用PRINT_FOR。它应该看起来更接近:

HashMap

<小时/> 更新:根据您的评论,您基本上希望同时将所有3个报告导出为一个。这可以通过使用JRPrintServiceExporter来实现。基本上创建三个Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("PRINT_FOR", "CLIENT"); 对象,并将它们放在一个列表中。然后使用导出器将其打印出来。类似的东西:

JasperPrint

答案 2 :(得分:0)

当您使用自己的JRBeanCollectionDataSource时,必须为每个JasperPrint创建各自的JRBeanCollectionDataSource

        JRBeanCollectionDataSource dsCliente = new JRBeanCollectionDataSource(listaDetalle);
        JasperPrint jasperPrintCliente = JasperFillManager.fillReport("plantillaDoc.jasper", paramsHojaCliente, dsCliente);
        listaJasperPrint.add(jasperPrintCliente);

        JRBeanCollectionDataSource dsCaja1 = new JRBeanCollectionDataSource(listaDetalle);
        JasperPrint jasperPrintCaja1 = JasperFillManager.fillReport("plantillaDoc.jasper", paramsHojaCaja, dsCaja1);
        listaJasperPrint.add(jasperPrintCaja1);