碧玉报告动态子报告生成 [英] jasper-reports dynamic sub report generation

查看:72
本文介绍了碧玉报告动态子报告生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用jasper-reports(不使用iReport)从Java代码生成报告.

I'm trying to generate a report from java code with jasper-reports (without iReport).

已成功创建以下元素:

  • 名为 reportDesign
  • 的主报表对象(类:JasperDesign)
  • 名为 subReportDesign
  • 的子报表对象(类:JasperDesign) 主报表中名为 subReportElement
  • SubReport元素(类:JRDesignSubreport)
  • 已编译的名为 subReport
  • 的子报表(类:JasperDesign)
  • Master report object (class: JasperDesign) named reportDesign
  • Sub report object (class: JasperDesign) named subReportDesign
  • SubReport element (class: JRDesignSubreport) in the Master report named subReportElement
  • Compiled Sub report (class: JasperDesign) named subReport

问题是,如何从 subReportElement 中引用 subReportDesign 对象?

The problem is, how do I reference the subReportDesign object from the subReportElement?

到目前为止,我发现的唯一方法是将 subReportElement 的表达式"字段设置为$P{REPORT_PARAMETERS_MAP}.get("subreportobject"),然后将 subReport 进入编译过程中的 reportDesign .

So far the only way I found, was to set subReportElement's "expression" field to $P{REPORT_PARAMETERS_MAP}.get("subreportobject"), and to put subReport into reportDesign during the compilation.

还有另一种方法吗?例如,我可以在编译主报告之前使用变量-以某种方式..-

Is there another way? For example can I use variables - in some way .. - before compiling the Master report?

谢谢, 克里斯蒂

推荐答案

如果子报表XML文件不在已知位置,则报表参数映射是唯一的方法.它确实需要我发现的临时文件,但这是几年前的事了.我进行了类似的设置(JRXML在数据库中).对于每个子报表,在编译主报告之前我都必须这样做:

If the subreport XML files are not in a known location, the report parameters map is the only way to do it. It does require temp files from what I found, but this was a couple of years ago. I've made a similar set up (JRXML is in a database). For each subreport I had to do this prior to compiling the master report:

 byte[] bytes = subreportXMLString.getBytes("UTF-8");
 InputStream input = new ByteArrayInputStream(bytes);

 File compiledReportFile = File.createTempFile(subreportParameterName, ".jasper");
 FileOutputStream buffer = new FileOutputStream(compiledReportFile);
 JasperCompileManager.compileReportToStream(input, buffer);
 input.close();
 buffer.close();
 reportParameters.put(subreportParameterName, compiledReportFile);

这篇关于碧玉报告动态子报告生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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