File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other JSE/JEE APIs and the fly likes Is dynamic columns possible in Jasperreport Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Is dynamic columns possible in Jasperreport" Watch "Is dynamic columns possible in Jasperreport" New topic

Is dynamic columns possible in Jasperreport

Rajan Chinna
Ranch Hand

Joined: Jul 01, 2004
Posts: 320
I have a requirement where I don't know how many columns my report is going to display until runtime. For example lets say if i want to display a report with 10 columns, first i should print the data with 4 columns followed by next 4 columns and the next 2 columns data.
Is it possible?
Please give me some ideas.....
Rajan Chinna
Ranch Hand

Joined: Jul 01, 2004
Posts: 320
Hi Joel McNary

Is it possible to do this in jasperreport???
Joel McNary

Joined: Aug 20, 2001
Posts: 1824

I've discovered that just about anything is possible in JasperReports. The problem here is that I don't think you can do this without interfacing with the JasperDesign object at runtime. That is, create your report with 1 column, and then at runtime load the design object and programatically change the columns.

If the API doesn't support it, you could always change the API to support it. (Jasper is OpenSource....)

Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Rajan Chinna
Ranch Hand

Joined: Jul 01, 2004
Posts: 320
Thanks Joel,

Do u think i can follow these steps ???
1. create .jrxml file programatically and dynamically.
2. compile it during runtime.
3. load data.
4. generate report.

Amit Siinngghh

Joined: Jun 19, 2004
Posts: 12
You can use IReport to create a template configuration file where you can set the font and other cosmetic things. Once you have finalised the looks then you can read the template xml configuration file at runtime and use JDOM to insert new columns or delete init columns. It involves very basic XML parsing and then rewriting the XML file back to the disk with new 'field' and other corresponding elements . Then jasperreport can pick the xml file from there.

One option could be to give jasperreport a runtime document object, but I havent tried it. Let us know if you can work around with it this way.

also refer to the dtd and before working on configuration file. Note that the XML file requires the elements to be in the same order as in the DTD. Some times when you insert new elements under the root they are inserted at the end of the document

Hope it helps

I agree. Here's the link:
subject: Is dynamic columns possible in Jasperreport
It's not a secret anymore!