iReport:如何隐藏带有文本字段的行而没有数据行包含不同种类的数据 [英] iReport: How to hide line with text fields without data line contains different kind of data

查看:49
本文介绍了iReport:如何隐藏带有文本字段的行而没有数据行包含不同种类的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将空文本字段(包含字符串或十进制值)放在为我的报告拉出的一行上,该字段显示空白行.

I have null textfields (it contains string or bigdecimal value) put on single line pulled for my report which display a blank line.

为了删除具有空行的空白行,我对该行中的报表元素使用了属性 isRemoveLineWhenBlank .但这是行不通的.

In order to remove the blank line that has null rows I used the property isRemoveLineWhenBlank for the report elements in that line. But that does not work.

有人可以帮我吗?

快照:

输出捕捉:

jrxml:

<?xml version="1.0" encoding="UTF-8"  ?>
<!-- Created with iReport - A designer for JasperReports -->
<!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
<jasperReport
         name="WEB_PREVIEW"
         columnCount="1"
         printOrder="Horizontal"
         orientation="Portrait"
         pageWidth="595"
         pageHeight="900"
         columnWidth="535"
         columnSpacing="0"
         leftMargin="30"
         rightMargin="30"
         topMargin="20"
         bottomMargin="20"
         whenNoDataType="NoPages"
         isTitleNewPage="false"
         isSummaryNewPage="false">
    <property name="ireport.scriptlethandling" value="0" />
    <property name="ireport.encoding" value="UTF-8" />
    <import value="java.util.*" />
    <import value="net.sf.jasperreports.engine.*" />
    <import value="net.sf.jasperreports.engine.data.*" />

    <parameter name="GROSS_RENTAL_INCOME_SQPA_LABEL" isForPrompting="false" class="java.lang.String"/>
    <parameter name="GROSS_RENTAL_INCOME_SQPA" isForPrompting="false" class="java.math.BigDecimal"/>
    <defaultValueExpression ><![CDATA["C:\\Development_New\\Cyprus\\Cyprus\\WebRoot\\report\\"]]></defaultValueExpression>
    </parameter>
    <background>
            <band height="0"  isSplitAllowed="true" >
            </band>
        </background>
        <title>
            <band height="0"  isSplitAllowed="true" >
            </band>
        </title>
        <pageHeader>
            <band height="32"  isSplitAllowed="true" >
                <textField isStretchWithOverflow="true" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self" >
                    <reportElement
                        x="367"
                        y="105"
                        width="96"
                        height="12"
                        key="textField"
                        positionType="Float"
                        isRemoveLineWhenBlank="true">
                            <printWhenExpression><![CDATA[new Boolean($P{GROSS_RENTAL_INCOME_SQPA}!=null)]]></printWhenExpression>
                        </reportElement>
                    <box></box>
                    <textElement>
                        <font pdfFontName="Helvetica-Bold" size="8" isBold="true"/>
                    </textElement>
                <textFieldExpression   class="java.lang.String"><![CDATA[$P{GROSS_RENTAL_INCOME_SQPA_LABEL}]]></textFieldExpression>
                </textField>
                <textField isStretchWithOverflow="true" pattern="###,##0.00" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self" >
                    <reportElement
                        x="472"
                        y="105"
                        width="48"
                        height="12"
                        key="textField"
                        positionType="Float"
                        isRemoveLineWhenBlank="true">
                            <printWhenExpression><![CDATA[new Boolean($P{GROSS_RENTAL_INCOME_SQPA}!=null)]]></printWhenExpression>
                        </reportElement>
                    <box></box>
                    <textElement>
                        <font size="8"/>
                    </textElement>
                <textFieldExpression   class="java.math.BigDecimal"><![CDATA[$P{GROSS_RENTAL_INCOME_SQPA}]]></textFieldExpression>
                </textField>
                </band>
        </detail>
        <columnFooter>
            <band height="0"  isSplitAllowed="true" >
            </band>
        </columnFooter>
        <pageFooter>
            <band height="0"  isSplitAllowed="true" >
            </band>
        </pageFooter>
        <summary>
            <band height="0"  isSplitAllowed="true" >
            </band>
        </summary>
</jasperReport>

推荐答案

您可以播放下面的示例以获得所需的结果.

You can play the sample below to achieve the result you want.

它演示了如何在 frame 元素的帮助下(当然与使用 一起使用)隐藏带有两个 textField 元素(两列)的行. isRemoveLineWhenBlank 属性(如问题中所述).

It's demonstrates how to hide the row with two textField elements (two columns) with help of frame elements (of course in cooperation with using isRemoveLineWhenBlank property as said in the question).

jrxml 文件代码:

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport ... pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" 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="139" splitType="Stretch">
            <line>
                <reportElement x="10" y="61" width="520" height="1"/>
            </line>
            <line>
                <reportElement x="10" y="127" width="520" height="1"/>
            </line>
            <textField isBlankWhenNull="true">
                <reportElement x="10" y="85" width="52" height="20" isRemoveLineWhenBlank="true"/>
                <box leftPadding="10">
                    <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="65" width="52" height="20" isRemoveLineWhenBlank="true"/>
                <box leftPadding="10">
                    <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="62" y="65" width="52" height="20" isRemoveLineWhenBlank="true"/>
                <box leftPadding="10">
                    <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="62" y="85" width="52" height="20" isRemoveLineWhenBlank="true"/>
                <box leftPadding="10">
                    <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>
                <reportElement x="331" y="65" width="52" height="54"/>
                <textField isBlankWhenNull="true">
                    <reportElement x="0" y="20" width="52" height="20" isRemoveLineWhenBlank="true"/>
                    <box leftPadding="10">
                        <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="0" y="0" width="52" height="20" isRemoveLineWhenBlank="true"/>
                    <box leftPadding="10">
                        <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="383" y="65" width="52" height="54"/>
                <textField isBlankWhenNull="true">
                    <reportElement x="0" y="0" width="52" height="20" isRemoveLineWhenBlank="true"/>
                    <box leftPadding="10">
                        <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="0" y="20" width="52" height="20" isRemoveLineWhenBlank="true"/>
                    <box leftPadding="10">
                        <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>
            <textField isStretchWithOverflow="true">
                <reportElement x="16" y="0" width="115" height="51"/>
                <box topPadding="10" leftPadding="10" bottomPadding="10" rightPadding="10"/>
                <textElement>
                    <font isBold="true" isItalic="true"/>
                </textElement>
                <textFieldExpression><![CDATA["P1: " + $P{par1} + "\nP2: " +  $P{par2} + "\nP3: " +  $P{par3} + "\nP4: " +  $P{par4}]]></textFieldExpression>
            </textField>
        </band>
    </title>
</jasperReport>

iReport 中的报告设计:

隐藏整行的结果:

隐藏第一列第一行中唯一字段的结果:

The result for hiding the only one field in first column, first row:

这篇关于iReport:如何隐藏带有文本字段的行而没有数据行包含不同种类的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆