Jump to content
Changes to the Jaspersoft community edition download ×

How to create dynamic columns in jasper report


Recommended Posts


I have a collection of data that I need to display in the report and create .PDF file after that. The problem is the size of collection is not fixed, and I don't know how to create report columns dynamically. For example, a collection of Dates {Date_1, Date_2, ..., Date_n}, each Date_# takes 1 column in the report. Please share with me if there are some ways to do that with Jasper Report.

Another small problem is how to wrap data in 1 cell of the report. I have a column called 'Name', some names are so long that they can't be displayed fully in a cell. Is there any way to wrap it?

Post edited by: greenfield82, at: 2008/04/27 18:47

Link to comment
Share on other sites

  • Replies 8
  • Created
  • Last Reply

Top Posters In This Topic

hi greenfield82



U can do this by using Velocity framework along with JasperReports.



Refer this link:





For the second problem you have mentioned, there will be an attribute called isStretchWithOverflow for every text field. Set that attribute to true. The text in the text field will get wrapped within the text field in the report



DNV Srikanth

Link to comment
Share on other sites


Sorry for my poor English.

When i faced the same ptoblem (dynamical column) i generateв reports on fly. Here java sample:


private JasperDesign getSubreportDesign( int aSubreportNumber, List<String> aColumnNames )

throws JRException {

JasperDesign jasperDesign = new JasperDesign();



// Dynamic columns



/ columnQtty;


for( int i = 0; i < columnQtty; i++ ) {

staticText = new JRDesignStaticText();

staticText.setX( start_x );

staticText.setY( 0 );

staticText.setWidth( dynamicColumnWidth );


staticText.setHorizontalAlignment( JRAlignment.HORIZONTAL_ALIGN_CENTER );

staticText.setVerticalAlignment( JRAlignment.VERTICAL_ALIGN_MIDDLE );

staticText.setText( convert2HTML(aColumnNames.get( i )) );

setBox( staticText, (i == (columnQtty - 1)) );

staticText.setStyledText( true );

band.addElement( staticText );

start_x += dynamicColumnWidth;



jasperDesign.setColumnHeader( band );


The same manner make detail fields

Link to comment
Share on other sites

  • 4 weeks later...
  • 1 month later...
Link to comment
Share on other sites

  • 8 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...