在iReport中使用条件格式 [英] Using conditional formatting in iReport
问题描述
我有一份提供数据表的报告。到目前为止,该报告运行良好。
现在我需要根据内容值对一些单元格进行着色。
我曾经在文本字段表达式中包含颜色方案,例如:
I have a report providing a table of data. The report works great so far.
Now I need to colourise some cells according to their content value.
I used to include the colour scheme in the Text Field Expression, for instance:
($F{MyBooleanValue}==true)?"<style backcolor='green'>PASS</style>":"<style backcolor='red'>FAIL</style>"
虽然有效,但它非常脏,无法管理和重复使用。
That works but it is quite dirty and a hell to manage and re-use.
所以我转向条件格式功能。我定义了一种名为 Colourised 的基础风格。然后是两个非常基本的条件样式:
So I turned to the Conditional formatting feature. I defined a based style called Colourised. Then two very basic conditional styles:
Colourised:
opaque = true
pass:
opaque = true
Condition Expression = "true"
Backcolor = [51,255,51]
fail:
opaque = true
Condition Expression = "false"
Backcolor = [255,102,102]
这通常应将单元格的背景颜色更改为绿色(独立于细胞价值)。
This should normally change the background colour of cells to green (independently from the cell value).
现在我尝试使用以下属性在我的单元格上使用此格式,但单元格仍保持绝对白色。
Now I try to use this formatting on my cell using the following properties, but the cells remain desperately white.
MyCell:
opaque = true
Text Field Expression = "$F{MyBooleanValue}"
Style = "Colourised"
我还设置了评估属性
<property name="net.sf.jasperreports.style.evaluation.time.enabled" value="true"/>
任何提示?有没有我忽略的东西?
Any hints? Is there something I overlooked?
推荐答案
好的,经过一番挖掘,我发现了细胞特性:
Ok, after a bit of digging, I found that the cell propertie:
MyCell:
Markup = "styled"
需要设置为:
MyCell:
Markup = "none"
然后背景显示正确的颜色。
Then the background display the proper colour.
这篇关于在iReport中使用条件格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!