jasper-reports dynamic sub report generation

感情迁移 提交于 2021-02-05 05:21:33

问题


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

Have successfully created the following elements:

  • 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

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

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?

thanks, krisy


回答1:


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);


来源:https://stackoverflow.com/questions/8256889/jasper-reports-dynamic-sub-report-generation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!