简体   繁体   English

如何使用JasperReports API以编程方式为替代行指定不同的背景颜色

[英]How to specify different background colors for alternative rows programatically with JasperReports API

I am creating JasperReports xls report with Java code (without using .jrxml). 我正在使用Java代码(不使用.jrxml)创建JasperReports xls报告。

I need to set different background colors for alternative rows in detail section. 我需要在详细信息部分为替代行设置不同的背景颜色。

How can i do it? 我该怎么做?

Use a style-definition at the beginning of your report: 在报告的开头使用样式定义:

<style name="DataCellStyle" mode="Opaque" border="None">
  <conditionalStyle>
    <conditionExpression>
      <![CDATA[new Boolean($V{REPORT_COUNT}.intValue() % 2 == 0)]]>
    </conditionExpression>
    <style mode="Opaque" backcolor="#E0E0E0" />
  </conditionalStyle>
</style>

...and use this style for your data-cells: ...并将这种样式用于您的数据单元:

<detail>
  <band height="15">
    <textField>
      <reportElement x="0" y="0" width="150" height="15" style="DataCellStyle"/>
      <textFieldExpression class="java.lang.String">
        <!-- something -->
      </textFieldExpression>
    </textField>
  </band>
</detail>

More info about conditional styles is here 有关条件样式的更多信息在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM