Report Formatting
I'm working in Jaspersoft Studio to tweak our reports. I have been unable to find a way to do two things and I'm wondering if it has to do with how the data is formatted.
1. I am unable to force dates into double digits or omit time values. I want 1/1/2020 12:00AM to display as 01/01/2020.
2. When items are contents of another item, they nest with indents. I want associated notes to share the same indent. I have not found any way to inherit an indent.
Help with either issue would be greatly appreciated.
-
Hi Andrew-
1. Most likely the data comes into the report as a text string, not as an actual date, so normal methods for date formatting will not work. The method for reformatting a date which is in string format is to use SimpleDateFormat to parse the string into a date and then format it as desired.
Put the following code in your text element. I've taken a stab at the input parse string (the second one) and the output format strings (first one) but you may need to adjust. I've done this in American format, you should swap the M's and d's if you're in the rest of the world. Also change the field name at the end to your input field. See https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html for all available format characters.
new SimpleDateFormat("MM/dd/yyyy").format((new SimpleDateFormat("M/d/yyyy HH:mma")).parse($F{dateStringField}))
2. Just to clarify - are you saying that if an item is indented, you also want the note to be indented? Use a conditional style.
- Create a style called Note with indent 0
- Add a conditional style with condition $F{description}.startsWith(" ") - this means the conditional style will activate when the item description starts with spaces, which is how the indent comes through in the report data.
- Set the indent in the conditional style to your desired amount
- Set the note text element in the detail band to use the Note style. Now it will be indented when the description is indented.
If you need any more help on these, feel free to reach out to me via email.
Cheers,
Benjamin 'Bigs' Coppel
Endorsed Flex Consultant and Report Developer
bigs@squarewave.com.au
www.squarewave.com.au -
Hi Andrew-
I replied but the post is pending approval for some reason. Re-posting here, hopefully it works this time:
Hi Andrew-
1. Most likely the data comes into the report as a text string, not as an actual date, so normal methods for date formatting will not work. The method for reformatting a date which is in string format is to use SimpleDateFormat to parse the string into a date and then format it as desired.
Put the following code in your text element. I've taken a stab at the input parse string (the second one) and the output format strings (first one) but you may need to adjust. I've done this in American format, you should swap the M's and d's if you're in the rest of the world. Also change the field name at the end to your input field. Google 'simpledateformat reference java platform SE 7' for the full reference with all allowed characters.
new SimpleDateFormat("MM/dd/yyyy").format((new SimpleDateFormat("M/d/yyyy HH:mma")).parse($F{dateStringField}))
2. Just to clarify - are you saying that if an item is indented, you also want the note to be indented? Use a conditional style.
- Create a style called Note with indent 0
- Add a conditional style with condition $F{description}.startsWith(" ") - this means the conditional style will activate when the item description starts with spaces, which is how the indent comes through in the report data.
- Set the indent in the conditional style to your desired amount
- Set the note text element in the detail band to use the Note style. Now it will be indented when the description is indented.
If you need any more help on these, feel free to reach out to me via email.
Cheers,
Benjamin 'Bigs' Coppel
Endorsed Flex Consultant and Report Developer
Please sign in to leave a comment.
Comments
3 comments