如果我在iReports设计器中创建Jasper报告模板文件,是否可以防止在其数据源中的字段为空时显示静态文本字段?
我知道我可以使用一定数量的JavaScript来处理报表中的数据 . 如果字段值为NULL或为空,是否可能隐藏元素?
如果字段值为NULL或为空,是否可能隐藏元素?
对的,这是可能的 .
1. Using "Print When Expression" property for static and text fields
用于隐藏NULL或“空”字符串值的示例:
<staticText> <reportElement x="52" y="16" width="100" height="20"> <printWhenExpression><![CDATA[$F{field1} != null && $F{field1}.trim().length()>0]]></printWhenExpression> </reportElement> <textElement/> <text><![CDATA[Static text]]></text> </staticText> <textField> <reportElement x="170" y="15" width="100" height="20"> <printWhenExpression><![CDATA[$F{field2} != null && $F{field2}.trim().length()>0]]></printWhenExpression> </reportElement> <textElement/> <textFieldExpression><![CDATA[$F{field2}]]></textFieldExpression> </textField>
2. Using "Blank When Null" property for text fields
隐藏带有NULL值的文本字段的示例:
<textField isBlankWhenNull="true"> <reportElement x="340" y="15" width="100" height="20"/> <textElement/> <textFieldExpression><![CDATA[$F{field3}]]></textFieldExpression> </textField>
3. Using "No Data" band for empty datasource - no data returns
如果datasource为空,则可以将“No Data”波段与您需要的静态字段一起使用 . 要使用此频段,您必须将“无数据时”报告的属性设置为“无数据部分” .
样品:
<?xml version="1.0" encoding="UTF-8"?> <jasperReport .. whenNoDataType="NoDataSection" ..> ... <noData> <band height="50"> <staticText> <reportElement x="236" y="18" width="100" height="20"/> <textElement/> <text><![CDATA[No data]]></text> </staticText> </band> </noData> </jasperReport>
1 回答
对的,这是可能的 .
1. Using "Print When Expression" property for static and text fields
用于隐藏NULL或“空”字符串值的示例:
2. Using "Blank When Null" property for text fields
隐藏带有NULL值的文本字段的示例:
3. Using "No Data" band for empty datasource - no data returns
如果datasource为空,则可以将“No Data”波段与您需要的静态字段一起使用 . 要使用此频段,您必须将“无数据时”报告的属性设置为“无数据部分” .
样品: