I want to get color to alternate for the rows in a JasperReports subreport. I have all rows with the same background color but I want it to alternate. Can this be done?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Yes you can set up a style inside the JRXML file like this:
<style name="Zebra" mode="Transparent">
<conditionalStyle>
<conditionExpression><![CDATA[$V{REPORT_COUNT}%2 == 1]]></conditionExpression>
<style backcolor="#CAC5BB"/>
</conditionalStyle>
</style>
and add it to your report elements like this:
<reportElement style="Zebra" mode="Opaque" x="1" y="1" width="554" height="20"/>
You cannot add conditional styles to style template files (e.g., .jrtx
files).
回答2:
If you are not using "styles", you can have a static text field (with no text) or a rectangle with the background color that you need, overlapping the textfield with data and set the printWhenExpression to $V{report_COUNT}%2 == 1
OR $V{report_COUNT}%2 == 0