如何以3个样本打印碧玉报告,几乎没有变化? [英] How to print a jasper report in 3 exemplar with little changes?
问题描述
我用iReport创建了一个jasper报告,我可以完美地打印出来。
我需要打印3个例子(原始示例,客户端示例,部门示例),只需更改一些,例如更改报告中的标签。
I've created a jasper report with iReport and I can print it perfectly. I need to print 3 examples of it (original example, client example, department example) with very few changes, for example changing a label in the report.
我将 PRINT_FOR
作为参数传递给iReport。
I pass PRINT_FOR
as parameter to 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))
推荐答案
您可以使用允许您使用和表达的文本字段
,而不是使用静态文本
字段确定文本输出。在这种情况下,您将检查 PRINT_FOR
参数是否等于客户端或部门,如果不使用原始值。你的表达式看起来像这样:
Instead of using a Static Text
field you can use a Text Field
that allows you to use and expression to determine the text output. In this case you would check to see if the PRINT_FOR
parameter is equal to the client or department and if not use the original value. You expression would look something like this:
($P{PRINT_FOR}.equals("DEPARTMENT") ? "Department Label" : ($P{PRINT_FOR}.equals("CLIENT") ? "Client Label" : "Original Label"))
当 PRINT_FOR
等于 DEPARMTNENT时输出
部门标签
code>,当
PRINT_FOR
等于客户端时输出客户标签
如果不等于上述任何一个,则输出code>和原始标签
。
Where Department Label
is outputted when PRINT_FOR
is equal to DEPARMTNENT
, Client Label
is outputted when PRINT_FOR
is equal to Client
, and Original Label
is outputted if it is not equal to either of the above.
另外值得注意的是,在您的代码片段中,您从未在Java代码中设置 PRINT_FOR
参数的值,并且您没有使用泛型 HashMap
。它应该看起来更接近:
Also worth noting is that in the code snippet about you never set the value for the PRINT_FOR
parameter in your java code and you are not using a generic HashMap
. It should look something closer to:
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("PRINT_FOR", "CLIENT");
更新:根据您的评论,你基本上想要同时将所有3个报告导出为一个。这可以通过使用
来实现。 JRPrintServiceExporter
。基本上创建三个 JasperPrint
对象,并将它们放在一个列表中。然后使用导出器将其打印出来。类似于:
UPDATE: Based on your comment, you basically want to do export all 3 reports as one at the same time. This can be accomplised by using the
JRPrintServiceExporter
. Basically create the three JasperPrint
Objects, and put them in a list. Then use the exporter to print them out. Something like:
//add all three JasperPrints to the list below
List<JasperPrint> jasperPrints = new ArrayList<JasperPrint>();
...
//create an exporter
JRExporter exporter = new JRPrintServiceExporter();
//add the JasperPrints to the exporter via the JASPER_PRINT_LIST param
exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, jasperPrints);
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE);
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.TRUE);
//this one makes it so that the settings choosen in the first dialog will be applied to the
//other documents in the list also
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG_ONLY_ONCE, Boolean.TRUE);
exporter.exportReport();
这篇关于如何以3个样本打印碧玉报告,几乎没有变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!