Showing posts with label formatting. Show all posts
Showing posts with label formatting. Show all posts

Monday, April 29, 2013

Jasper Reports: Highlight Every Other Row

Here is a quick guide to highlight every other row in a Jasper report (5.0.0).

Step 1. Get your rows formatted how you want.
Step 2.  Add a Static Text item that spans the entire length of your row.
Step 3.  Delete the default text.
Step 4.  Set the background color to whatever you want
Step 5.  Check the 'Opaque' checkbox, it should be covering your row now
Step 6.  Right click on the static text item and select 'Send to back'
Step 7.  In the Print When Expression enter: new Boolean( $V{PAGE_COUNT}.intValue() % 2 ==0 )

And that should do it. Every second row should show as highlighted.

Tuesday, October 16, 2012

Using String.format with Dates, Decimals and other cool things

Formatting Strings can become pretty cumbersome when you need to create a formatter object to handle a variety of different classes. Java does provide a pretty simple way to format many data types with the String.format method, but it can be hard to remember all the ways it can be used. Here are some examples to act as a reminder.

Date/Time

For more date/time formatting see here

Decimals and Money

Gotcha: If you are specifying each argument by it's index (%1, %2, etc) you need to add the '$' before any formatting, i.e. %2$.2f

Special Flags and New Line

You can also use special flags such as negative numbers in parans, zero-padding, and comma grouping
These examples cover the most common use cases of String formatting, but for more information you can check out the javadocs

Thursday, August 9, 2012

Removing White Space/Rows From Jasper XLS Reports

Jasper Reports likes to add extra cells and rows for formatting, but if all you're trying to do is show tabular data you probably don't want that extra space.

Here are the things to set and look out for to remove all the extra white space:

Set Ignore Pagination

On the jasper Report element you want to set <jasperReport isIgnorePagination="true"...  This will remove any extra rows that could be added at the end of the page.


Remove Empty Space

The JR XLS exporter allows certain properties in order to remove extra spacing cells and rows.  You will want to set these to true, like so (This example it is adding them to a ModelAndView Object in SpringMVC, but they would be the same for any XLS exporter):
mav.addObject(JRXlsExporterParameter.PROPERTY_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE); mav.addObject(JRXlsExporterParameter.PROPERTY_REMOVE_EMPTY_SPACE_BETWEEN_COLUMNS, Boolean.TRUE);

Remove Line When Blank

If you're using a table element you'll want to set the <reportElement isRemoveLineWhenBlank="true"... so there are no empty rows.  I'm not sure how applicable this attribute is on non-table elements.

Remove Extra Space From Your Design

Jasper will fill in extra white space that you have in your report design with cells.  To avoid this you want to make sure that your band's height is exactly equal to the elements in side of it.  

Table Height = the size of the cells inside
Band Height = the size of the elements inside it
Also, when putting your text and fields near each other make sure you line up everything exactly and that there is only about 1 pixel of space between them (Hint: zoom in, use the arrows to move objects around, and type in the height and widths instead of using the mouse).