我使用JasperReports 5.6.0生成报告。我正在生成不同格式的报告,如html,csv,pdf,xls,doc。在我的一份报告中,我有5个TextField。我想隐藏TextField null.suppose textField2为null然后隐藏和TextField3替换TextField2的位置。为此,我使用printWhenExpression。现在它隐藏textField为null但问题是该textfield占用的空间保持不变。
当textField为空时,如何删除textField中的空白区域?
以下代码用于了解我如何使用它。
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="RemoveSpace Ex" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="d8585174-6b4e-4746-a5fe-2dfd5af32a61">
<parameter name="ABC" class="java.lang.Boolean">
<defaultValueExpression><![CDATA[false]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[select * from Student]]>
</queryString>
<field name="ID" class="java.math.BigDecimal"/>
<field name="FIRSTNAME" class="java.lang.String"/>
<field name="LASTNAME" class="java.lang.String"/>
<field name="USERNAME" class="java.lang.String"/>
<field name="PASSWORD" class="java.lang.String"/>
<field name="PHONE" class="java.lang.String"/>
<title>
<band height="79" splitType="Stretch">
<staticText>
<reportElement x="139" y="13" width="279" height="20" uuid="e1b06699-645f-4906-9066-f3cd1ed70d81"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font isBold="true" isItalic="true"/>
</textElement>
<text><![CDATA[Sample of hiding column]]></text>
</staticText>
<textField>
<reportElement x="189" y="33" width="211" height="20" uuid="b619aa59-f5e6-465c-b303-4a5a5879e0f4"/>
<box leftPadding="10"/>
<textFieldExpression><![CDATA["To hide Street column: " + $P{ABC}]]></textFieldExpression>
</textField>
</band>
</title>
<detail>
<band height="125" splitType="Stretch">
<textField>
<reportElement x="100" y="0" width="500" height="20" uuid="15d3a067-378f-4ec5-a325-446142c18bea">
<printWhenExpression><![CDATA[$P{ABC}]]></printWhenExpression>
</reportElement>
<box leftPadding="10"/>
<textFieldExpression><![CDATA[$F{FIRSTNAME}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="0" width="100" height="20" uuid="4c77324f-e097-45ce-b2bb-5103f19467d4"/>
<box leftPadding="10"/>
<textFieldExpression><![CDATA[$F{ID}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="100" y="0" width="100" height="20" uuid="df0c1287-3495-4e82-a630-5ac574812956">
<printWhenExpression><![CDATA[!$P{ABC}]]></printWhenExpression>
</reportElement>
<box leftPadding="10"/>
<textFieldExpression><![CDATA[$F{LASTNAME}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="200" y="0" width="100" height="20" uuid="f8393dbd-e99d-4aeb-b5ff-91810bd97d59">
<printWhenExpression><![CDATA[!$P{ABC}]]></printWhenExpression>
</reportElement>
<box leftPadding="10"/>
<textFieldExpression><![CDATA[$F{FIRSTNAME}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="300" y="0" width="100" height="20" uuid="f8393dbd-e99d-4aeb-b5ff-91810bd97d59">
<printWhenExpression><![CDATA[!$P{ABC}]]></printWhenExpression>
</reportElement>
<box leftPadding="10"/>
<textFieldExpression><![CDATA[$F{USERNAME}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="400" y="0" width="100" height="20" uuid="f8393dbd-e99d-4aeb-b5ff-91810bd97d59">
<printWhenExpression><![CDATA[!$P{ABC}]]></printWhenExpression>
</reportElement>
<box leftPadding="10"/>
<textFieldExpression><![CDATA[$F{PASSWORD}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="500" y="0" width="100" height="20" uuid="f8393dbd-e99d-4aeb-b5ff-91810bd97d59">
<printWhenExpression><![CDATA[!$P{ABC}]]> </printWhenExpression>
</reportElement>
<box leftPadding="10"/>
<textFieldExpression><![CDATA[$F{PHONE}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>