How to create a dynamic report thorough jrxml?

后端 未结 1 328
自闭症患者
自闭症患者 2021-01-03 00:59

I am working on jrxml to create dynamic reports. I have parameterized the columns i.e. the jrxml for that report can be used to generate other reports as w

相关标签:
1条回答
  • 2021-01-03 01:55

    In case you want it to be dynamic as in hiding/showing new fields, i think the only way would be to modify your jrxml at runtime and compile it.

    UPDATE:

    To make the JasperReport dynamic at runtime you have three approaches:

    1. Create JRXML in iReport
    If your report is complicated and have many subreports and subdatasets, its better to go this approach, since iReport will make it quicker and easier for you to design and maintain later.
    When following this approach you will create the jrxml file and store in the classpath, at runtime you will load this file, open it, and modify the XML tags you want. I would recommend to start with a jrxml that includes the max number of columns, and then if user select less columns then find those additional columns in the jrxml and delete them.

    2. Create whole report in Java
    This approach is better if your report is really simple, like a quick tabular report, in this case you dont need a jrxml file, you can create the whole report at runtime from scratch using JasperReport library APIs. This approach will make designing the report harder as you wont see anything until you compile and run. Yet worse its a maintenance nightmare.
    Your final Java source code will look something like this: "Fixed Column Width Test"1

    3. Use DynamicJasper
    Finally, if you are open to new tools, there is always DynamicJasper, you can check the online demo as well, its pretty cool.
    I kept DJ for the end to show you all the approaches, DJ actually uses the second one. Creating Java source code of the report on the fly.


    1: Fixed Column Width Test Report copyrights are for DynamicJasper and used here just as a sample.

    0 讨论(0)
提交回复
热议问题