views:

2095

answers:

2

Have you ever had alternating background colors in a Jasper report and then exported it to Excel? The Excel export seems to ignore the alternating color.

I've got a Jasper report where the rows alternating background color using the procedure referenced HERE. When I preview it using the viewer or export to PDF it works -- but not when I export to Excel. I've tried using JRXlsExporter and JExcelApiExporter both to no avail.

I think it might be a side-effect of how you have to make alternating row colors in Jasper, which I despise to begin with, but have found no other way.

Thanks in advance!

+2  A: 

Did you try the idea suggested in the comment of the very procedure you are referring to ?

First how to create new report style with condition:

Recent releases of JasperReports include report styles, which make this a bit easier - you no longer have to create the rectangle.

I use iReport to create my styles - there is a “styles” pane that by default is docked with the “Library” pane. If you make it visible you can create a new style in the styles library. In the screen that pops up give the style a name (say “EvenOddRowStyle” and press “Add” under “Style Conditions”. Use one of the expressions that Brian gave and press Apply. and in the “Common” section press the “…” button next to “Backcolor” and pick the background color you want. Finally, when done with your report apply that style to all the fields in the rows you want to highlight. Just drag the style from the styles pane onto the field.

Then how to define a style which will be applied when exported to Excel:

defining a new style with the condition expression:

Boolean.valueOf( $V{PAGE_COUNT}.intValue() % 2 == 0 )

on it without using a rectangle and a print when expression on it!

VonC
I have now and it works! I didn't realize on the link that there was a "show all comments" option, so I didn't review them. Thanks for pointing it out to me!This approach is waaaaay more elegant.Thanks again man!
discgolfer
A: 

Also, Be sure that the conditional styles you make, have the "opaque" option checked... If not, the background color will never apper in the excel report (never!!!)....

Also, The "opaque" option must be checked in the text fields....

And if you noticed that the text fields never took the style that you gave to them, try to set the forecolor and background to null, in the properties panel of each text field (this works for me)...

Hope this help... bye.

Carlos Chacon