Bạn có thể sử dụng 3 textField
yếu tố với isRemoveLineWhenBlank
bất động sản thiết lập để giá trị true
.
Mẫu (jrxml tập tin):
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport .. topMargin="0" bottomMargin="0">
<parameter name="parameter1" class="java.lang.String">
<defaultValueExpression><![CDATA[null]]></defaultValueExpression>
</parameter>
<parameter name="parameter2" class="java.lang.String">
<defaultValueExpression><![CDATA[null]]></defaultValueExpression>
</parameter>
<parameter name="parameter3" class="java.lang.String">
<defaultValueExpression><![CDATA[null]]></defaultValueExpression>
</parameter>
<title>
<band height="102" splitType="Stretch">
<textField isBlankWhenNull="true">
<reportElement x="163" y="9" width="100" height="20" isRemoveLineWhenBlank="true"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$P{parameter1} == null ? null : "Parameter1: " + $P{parameter1}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement x="163" y="29" width="100" height="20" isRemoveLineWhenBlank="true"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$P{parameter2} == null ? null : "Parameter2: " + $P{parameter2}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement x="163" y="49" width="100" height="20" isRemoveLineWhenBlank="true"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$P{parameter3} == null ? null : "Parameter3: " + $P{parameter3}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="163" y="73" width="100" height="20"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement/>
<text><![CDATA[Static text]]></text>
</staticText>
<line>
<reportElement x="63" y="6" width="447" height="1"/>
</line>
<line>
<reportElement x="73" y="96" width="447" height="1"/>
</line>
</band>
</title>
</jasperReport>
Thiết kế báo cáo trong iReport
:
Đối với argument1 = null, argument2 = null, argument1 = VALUE3 kết quả sẽ là:
CẬP NHẬT
Đối với việc giải quyết vấn đề di chuyển lên textField
trong trường hợp các yếu tố trên đã giấu bạn có thể sử dụng container Frame
.Bạn nên thêm 2 khung hình (một khung cho mỗi cột) và đặt các thành phần 2 textField
(2 hàng) vào mỗi khung.
Mẫu (jrxml tập tin):
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport .. topMargin="0" bottomMargin="0">
<parameter name="par1" class="java.lang.String">
<defaultValueExpression><![CDATA[null]]></defaultValueExpression>
</parameter>
<parameter name="par2" class="java.lang.String">
<defaultValueExpression><![CDATA[null]]></defaultValueExpression>
</parameter>
<parameter name="par3" class="java.lang.String">
<defaultValueExpression><![CDATA[null]]></defaultValueExpression>
</parameter>
<parameter name="par4" class="java.lang.String">
<defaultValueExpression><![CDATA[null]]></defaultValueExpression>
</parameter>
<title>
<band height="80" splitType="Stretch">
<line>
<reportElement x="10" y="6" width="520" height="1"/>
</line>
<line>
<reportElement x="10" y="72" width="520" height="1"/>
</line>
<frame>
<reportElement x="329" y="10" width="172" height="59"/>
<frame>
<reportElement x="13" y="3" width="60" height="54"/>
<textField isBlankWhenNull="true">
<reportElement x="1" y="20" width="52" height="20" isRemoveLineWhenBlank="true"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$P{par3} == null ? null : "P3: " + $P{par3}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement x="1" y="0" width="52" height="20" isRemoveLineWhenBlank="true"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$P{par1} == null ? null : "P1: " + $P{par1}]]></textFieldExpression>
</textField>
</frame>
<frame>
<reportElement x="73" y="3" width="70" height="54"/>
<textField isBlankWhenNull="true">
<reportElement x="1" y="0" width="52" height="20" isRemoveLineWhenBlank="true"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$P{par2} == null ? null : "P2: " + $P{par2}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement x="1" y="20" width="52" height="20" isRemoveLineWhenBlank="true"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$P{par4} == null ? null : "P4: " + $P{par4}]]></textFieldExpression>
</textField>
</frame>
</frame>
<textField isBlankWhenNull="true">
<reportElement x="10" y="30" width="52" height="20" isRemoveLineWhenBlank="true"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$P{par3} == null ? null : "P3: " + $P{par3}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement x="10" y="10" width="52" height="20" isRemoveLineWhenBlank="true"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$P{par1} == null ? null : "P1: " + $P{par1}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement x="64" y="10" width="52" height="20" isRemoveLineWhenBlank="true"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$P{par2} == null ? null : "P2: " + $P{par2}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement x="64" y="30" width="52" height="20" isRemoveLineWhenBlank="true"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$P{par4} == null ? null : "P4: " + $P{par4}]]></textFieldExpression>
</textField>
</band>
</title>
</jasperReport>
Thiết kế báo cáo trong iReport
:
Đối với par1 = null, par2 = 2, par3 = 3, par4 = 4 sự kết quả sẽ là:
Bạn có thể so sánh kết quả - bên trái được thực hiện mà không cần sử dụng frame
và bên phải có các thành phần frame
.
Nguồn
2012-04-10 08:15:53
Bạn có thể sử dụng một 'textField'. Bạn đang sử dụng loại vị trí nào (theo chiều dọc hoặc chiều ngang)? –
im sử dụng vertical.ydays, tôi đang sử dụng kết hợp tất cả trong một textfield và tôi đặt đường đôi. khi một trong ba không hiển thị. nó sẽ hiển thị 2 textfield. nhưng có không gian trong textfield. cách xóa không gian để báo cáo có thể hiển thị cấu trúc hơn? –