首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如果细节带中至少有一个null字段,则打印表达式以显示静态文本

如果细节带中至少有一个null字段,则打印表达式以显示静态文本
EN

Stack Overflow用户
提问于 2014-05-30 10:04:47
回答 2查看 14.9K关注 0票数 2

我想在静态文本上放置一个printWhenExpression,其条件是只有在特定列中的细节带中至少有一个非空textField时才打印标签。

只有当列中有非空字段时,才打印列标题。

我试着放置这个表达式:$F{textfield} != null,但是它只适用于第一条记录,如果第一条记录有空,第二条记录没有空值,那么标签就会被隐藏,就像我们想要显示的那样。

如果您需要更多的信息,请回复。

下面是我的.jrxml文件。

代码语言:javascript
复制
<?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="IdpPdfSignature1" pageWidth="296" pageHeight="300" whenNoDataType="AllSectionsNoDetail" columnWidth="296" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="1c6e4be1-891b-4d0e-abfd-1c17f663d5be">
    <property name="ireport.scriptlethandling" value="0"/>
    <property name="ireport.encoding" value="UTF-8"/>
    <import value="net.sf.jasperreports.engine.*"/>
    <import value="java.util.*"/>
    <import value="net.sf.jasperreports.engine.data.*"/>
    <parameter name="mypic" class="java.io.InputStream" isForPrompting="false"/>
    <parameter name="mypic1" class="java.io.InputStream" isForPrompting="false"/>
    <parameter name="mypic2" class="java.io.InputStream" isForPrompting="false"/>
    <parameter name="group" class="java.lang.String" isForPrompting="false"/>
    <parameter name="device" class="java.lang.String" isForPrompting="false"/>
    <parameter name="timeperiod" class="java.lang.String" isForPrompting="false"/>
    <parameter name="customStartDate" class="java.util.Date" isForPrompting="false"/>
    <parameter name="customEndDate" class="java.util.Date" isForPrompting="false"/>
    <parameter name="footer" class="java.lang.String" isForPrompting="false"/>
    <field name="signatureID" class="java.lang.String">
        <fieldDescription><![CDATA[signatureID]]></fieldDescription>
    </field>
    <field name="signatureClassification" class="java.lang.String">
        <fieldDescription><![CDATA[signatureClassification]]></fieldDescription>
    </field>
    <field name="description" class="java.lang.String">
        <fieldDescription><![CDATA[description]]></fieldDescription>
    </field>
    <field name="count" class="java.lang.Long">
        <fieldDescription><![CDATA[count]]></fieldDescription>
    </field>
    <field name="formattedCount" class="java.lang.String"/>
    <field name="messageType" class="java.lang.String"/>
    <variable name="mypic" class="java.io.InputStream"/>
    <variable name="mypic1" class="java.io.InputStream"/>
    <variable name="mypic2" class="java.io.InputStream"/>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band splitType="Stretch"/>
    </title>
    <pageHeader>
        <band splitType="Stretch"/>
    </pageHeader>
    <columnHeader>
        <band height="16" splitType="Stretch">
            <staticText>
                <reportElement key="staticText-2" mode="Opaque" x="0" y="0" width="160" height="16" forecolor="#000000" backcolor="#CCCCCC" uuid="967c915b-1af1-4972-805f-0e3f365ba11c">
                    <printWhenExpression><![CDATA[new Boolean($F{messageType}!=null)]]></printWhenExpression>
                </reportElement>
                <box>
                    <pen lineWidth="0.25" lineColor="#000000"/>
                    <topPen lineWidth="0.25" lineColor="#000000"/>
                    <leftPen lineWidth="0.25" lineColor="#000000"/>
                    <bottomPen lineWidth="0.25" lineColor="#000000"/>
                    <rightPen lineWidth="0.25" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font fontName="Arial" size="10" isBold="true" pdfFontName="Helvetica-Bold"/>
                </textElement>
                <text><![CDATA[Signature Name]]></text>
            </staticText>
            <staticText>
                <reportElement key="staticText-3" mode="Opaque" x="210" y="0" width="86" height="16" forecolor="#000000" backcolor="#CCCCCC" uuid="a998a72e-01fa-4c27-ad7e-1e3a6c3408d2"/>
                <box>
                    <pen lineWidth="0.25" lineColor="#000000"/>
                    <topPen lineWidth="0.25" lineColor="#000000"/>
                    <leftPen lineWidth="0.25" lineColor="#000000"/>
                    <bottomPen lineWidth="0.25" lineColor="#000000"/>
                    <rightPen lineWidth="0.25" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font fontName="Arial" size="10" isBold="true" pdfFontName="Helvetica-Bold"/>
                </textElement>
                <text><![CDATA[Event Count]]></text>
            </staticText>
            <staticText>
                <reportElement key="staticText-11" mode="Opaque" x="160" y="0" width="50" height="16" forecolor="#000000" backcolor="#CCCCCC" uuid="5170b4a6-3531-412d-9f8f-bc32dc4de0be">
                    <printWhenExpression><![CDATA[new Boolean($F{messageType}!=null)]]></printWhenExpression>
                </reportElement>
                <box>
                    <pen lineWidth="0.25" lineColor="#000000"/>
                    <topPen lineWidth="0.25" lineColor="#000000"/>
                    <leftPen lineWidth="0.25" lineColor="#000000"/>
                    <bottomPen lineWidth="0.25" lineColor="#000000"/>
                    <rightPen lineWidth="0.25" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font fontName="Arial" size="10" isBold="true" pdfFontName="Helvetica-Bold"/>
                </textElement>
                <text><![CDATA[Type]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="16" splitType="Stretch">
            <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                <reportElement key="textField-7" stretchType="RelativeToTallestObject" x="160" y="0" width="50" height="16" uuid="917d3aff-44a7-4a26-865a-d466aff3ab00">
                    <printWhenExpression><![CDATA[new Boolean($F{messageType}!=null)]]></printWhenExpression>
                </reportElement>
                <box leftPadding="5">
                    <topPen lineWidth="0.25" lineColor="#999999"/>
                    <leftPen lineWidth="0.25" lineColor="#999999"/>
                    <bottomPen lineWidth="0.25" lineColor="#999999"/>
                    <rightPen lineWidth="0.25" lineColor="#999999"/>
                </box>
                <textElement textAlignment="Left">
                    <font fontName="Arial"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{messageType}]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                <reportElement key="textField" stretchType="RelativeToTallestObject" x="0" y="0" width="160" height="16" uuid="72492119-a45f-49c5-8fb8-19252c57e402">
                    <printWhenExpression><![CDATA[new Boolean($F{messageType}!=null)]]></printWhenExpression>
                </reportElement>
                <box leftPadding="5" rightPadding="10">
                    <topPen lineWidth="0.25" lineColor="#999999"/>
                    <leftPen lineWidth="0.25" lineColor="#999999"/>
                    <bottomPen lineWidth="0.25" lineColor="#999999"/>
                    <rightPen lineWidth="0.25" lineColor="#999999"/>
                </box>
                <textElement>
                    <font fontName="Arial"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{signatureClassification}]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                <reportElement key="textField" stretchType="RelativeToTallestObject" x="210" y="0" width="86" height="16" uuid="223be44f-8565-40e3-9d43-0f13b4e159b7"/>
                <box leftPadding="5" rightPadding="10">
                    <topPen lineWidth="0.25" lineColor="#999999"/>
                    <leftPen lineWidth="0.25" lineColor="#999999"/>
                    <bottomPen lineWidth="0.25" lineColor="#999999"/>
                    <rightPen lineWidth="0.25" lineColor="#999999"/>
                </box>
                <textElement textAlignment="Right">
                    <font fontName="Arial"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{formattedCount}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
    <columnFooter>
        <band splitType="Stretch"/>
    </columnFooter>
    <pageFooter>
        <band splitType="Stretch"/>
    </pageFooter>
    <summary>
        <band splitType="Stretch"/>
    </summary>
</jasperReport>
EN

回答 2

Stack Overflow用户

发布于 2014-06-03 09:55:11

您可以使用Table组件来实现这一点,而不是使用静态文本,方法是在表的列标题的“列打印时”属性下提供“打印时条件”。

即列打印时间= $F{messageType}!=null

PFB修正了JRXML:

代码语言:javascript
复制
<summary>

    <band height="55" splitType="Stretch">
        <componentElement>
            <reportElement uuid="632c8fad-e35f-4b89-b28e-b363b0711c06" x="0" y="0" width="270" height="55"/>
            <jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
                <datasetRun subDataset="Table Dataset 1" uuid="bf16282a-8672-46cb-9849-4966b5f8c969">
                    <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource(1)]]></dataSourceExpression>
                </datasetRun>
                <jr:column width="90" uuid="00429e67-6d71-4b66-9eb4-22d0c649e7a4">
                    <jr:columnHeader height="30" rowSpan="1">
                        <staticText>
                            <reportElement uuid="a62a81ca-ceae-4178-9e4e-6ca17fc89c69" key="staticText-2" mode="Opaque" x="0" y="0" width="90" height="30" forecolor="#000000" backcolor="#CCCCCC">
                                <printWhenExpression><![CDATA[new Boolean($F{messageType}!=null)]]></printWhenExpression>
                            </reportElement>
                            <box>
                                <pen lineWidth="0.25" lineColor="#000000"/>
                                <topPen lineWidth="0.25" lineColor="#000000"/>
                                <leftPen lineWidth="0.25" lineColor="#000000"/>
                                <bottomPen lineWidth="0.25" lineColor="#000000"/>
                                <rightPen lineWidth="0.25" lineColor="#000000"/>
                            </box>
                            <textElement textAlignment="Center" verticalAlignment="Middle">
                                <font fontName="Arial" isBold="true" pdfFontName="Helvetica-Bold"/>
                            </textElement>
                            <text><![CDATA[Signature Name]]></text>
                        </staticText>
                    </jr:columnHeader>
                    <jr:detailCell height="20" rowSpan="1">
                        <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                            <reportElement uuid="cb654043-45a4-4742-86ed-ed9818716db2" key="textField" stretchType="RelativeToTallestObject" x="0" y="0" width="90" height="20">
                                <printWhenExpression><![CDATA[new Boolean($F{messageType}!=null)]]></printWhenExpression>
                            </reportElement>
                            <box leftPadding="5" rightPadding="10">
                                <topPen lineWidth="0.25" lineColor="#999999"/>
                                <leftPen lineWidth="0.25" lineColor="#999999"/>
                                <bottomPen lineWidth="0.25" lineColor="#999999"/>
                                <rightPen lineWidth="0.25" lineColor="#999999"/>
                            </box>
                            <textElement>
                                <font fontName="Arial"/>
                            </textElement>
                            <textFieldExpression><![CDATA[$F{signatureClassification}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
                <jr:column width="90" uuid="7ebf1fdd-52e5-43da-96f0-1c01a7cb0876">
                    <printWhenExpression><![CDATA[$F{messageType}!=null]]></printWhenExpression>
                    <jr:columnHeader height="30" rowSpan="1">
                        <staticText>
                            <reportElement uuid="d96cce84-1318-49aa-a6d2-3a17e4329ef3" key="staticText-11" mode="Opaque" x="0" y="0" width="90" height="30" forecolor="#000000" backcolor="#CCCCCC">
                                <printWhenExpression><![CDATA[new Boolean($F{messageType}!=null)]]></printWhenExpression>
                            </reportElement>
                            <box>
                                <pen lineWidth="0.25" lineColor="#000000"/>
                                <topPen lineWidth="0.25" lineColor="#000000"/>
                                <leftPen lineWidth="0.25" lineColor="#000000"/>
                                <bottomPen lineWidth="0.25" lineColor="#000000"/>
                                <rightPen lineWidth="0.25" lineColor="#000000"/>
                            </box>
                            <textElement textAlignment="Center" verticalAlignment="Middle">
                                <font fontName="Arial" isBold="true" pdfFontName="Helvetica-Bold"/>
                            </textElement>
                            <text><![CDATA[Type]]></text>
                        </staticText>
                    </jr:columnHeader>
                    <jr:detailCell height="20" rowSpan="1">
                        <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                            <reportElement uuid="4832a90d-505e-4f13-87bf-0a7fe6e3a00f" key="textField-7" stretchType="RelativeToTallestObject" x="0" y="0" width="90" height="20">
                                <printWhenExpression><![CDATA[$F{messageType}]]></printWhenExpression>
                            </reportElement>
                            <box leftPadding="5">
                                <topPen lineWidth="0.25" lineColor="#999999"/>
                                <leftPen lineWidth="0.25" lineColor="#999999"/>
                                <bottomPen lineWidth="0.25" lineColor="#999999"/>
                                <rightPen lineWidth="0.25" lineColor="#999999"/>
                            </box>
                            <textElement textAlignment="Left">
                                <font fontName="Arial"/>
                            </textElement>
                            <textFieldExpression><![CDATA[$F{messageType}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
                <jr:column width="90" uuid="89b50640-0509-4b61-8aa3-aa68eb3e6685">
                    <jr:columnHeader height="30" rowSpan="1">
                        <staticText>
                            <reportElement uuid="fe68d8bf-3f0d-4202-a53c-8c6f328e4d16" key="staticText-3" mode="Opaque" x="0" y="0" width="90" height="30" forecolor="#000000" backcolor="#CCCCCC"/>
                            <box>
                                <pen lineWidth="0.25" lineColor="#000000"/>
                                <topPen lineWidth="0.25" lineColor="#000000"/>
                                <leftPen lineWidth="0.25" lineColor="#000000"/>
                                <bottomPen lineWidth="0.25" lineColor="#000000"/>
                                <rightPen lineWidth="0.25" lineColor="#000000"/>
                            </box>
                            <textElement textAlignment="Center" verticalAlignment="Middle">
                                <font fontName="Arial" isBold="true" pdfFontName="Helvetica-Bold"/>
                            </textElement>
                            <text><![CDATA[Event Count]]></text>
                        </staticText>
                    </jr:columnHeader>
                    <jr:detailCell height="20" rowSpan="1">
                        <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                            <reportElement uuid="169af53a-b587-4d63-93f8-cb9296c89f4c" key="textField" stretchType="RelativeToTallestObject" x="0" y="0" width="90" height="20"/>
                            <box leftPadding="5" rightPadding="10">
                                <topPen lineWidth="0.25" lineColor="#999999"/>
                                <leftPen lineWidth="0.25" lineColor="#999999"/>
                                <bottomPen lineWidth="0.25" lineColor="#999999"/>
                                <rightPen lineWidth="0.25" lineColor="#999999"/>
                            </box>
                            <textElement textAlignment="Right">
                                <font fontName="Arial"/>
                            </textElement>
                            <textFieldExpression><![CDATA[$F{formattedCount}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
            </jr:table>
        </componentElement>
    </band>
</summary>

希望这能解决你的问题。

致以敬意,

斯里坎·卡塔姆

票数 0
EN

Stack Overflow用户

发布于 2022-08-26 07:58:48

使用设置为“Count”的变量将允许您检查该字段是否至少包含一个非空值。因为我们只能知道,在所有记录都被处理之后,我们必须将列标题上的评估时间配置为“Report”,而不是现在。Eval时间不能设置为“静态文本”,但我们可以使用“文本字段”代替。此外,Eval时间不适用于“打印时”表达式,因为报表引擎需要知道我们是否正在绘制元素,而当我们仍在列标题时无法确定该元素是否正在绘制。使用一个根据count变量导致null的表达式解决了这个问题(使用“空时空白”)。

示例:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.19.1.final using JasperReports Library version 6.1.1  -->
<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="Blank_A45" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="81b8aa8f-65d7-4eec-b9de-322d7c5d185d">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="technotrix_dev"/>
    <property name="com.jaspersoft.studio.data.sql.tables" value=""/>
    <queryString>
        <![CDATA[SELECT null as field1, null as field2
UNION ALL 
SELECT null as field1, 'foobar' as field2
UNION ALL 
SELECT null as field1, null as field2]]>
    </queryString>
    <field name="field1" class="java.lang.String">
        <property name="com.jaspersoft.studio.field.name" value="field1"/>
        <property name="com.jaspersoft.studio.field.label" value="field1"/>
    </field>
    <field name="field2" class="java.lang.String">
        <property name="com.jaspersoft.studio.field.name" value="field2"/>
        <property name="com.jaspersoft.studio.field.label" value="field2"/>
    </field>
    <variable name="field1_count" class="java.lang.Integer" calculation="Count">
        <variableExpression><![CDATA[$F{field1}]]></variableExpression>
    </variable>
    <variable name="field2_count" class="java.lang.Integer" calculation="Count">
        <variableExpression><![CDATA[$F{field2}]]></variableExpression>
    </variable>
    <columnHeader>
        <band height="61" splitType="Stretch">
            <textField evaluationTime="Report" isBlankWhenNull="true">
                <reportElement x="0" y="0" width="210" height="20" uuid="aaf98575-6e1e-4839-be84-b3bc37d14653">
                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="bf75b6ee-b46c-4aa6-9f57-d15a9c87f716"/>
                </reportElement>
                <textElement>
                    <font isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA[$V{field1_count} > 0 ? "field1" : null]]></textFieldExpression>
            </textField>
            <textField evaluationTime="Report" isBlankWhenNull="true">
                <reportElement x="240" y="0" width="210" height="20" uuid="b6eba88b-e9c0-4b18-bf12-56944b2c55a1">
                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="bf75b6ee-b46c-4aa6-9f57-d15a9c87f716"/>
                </reportElement>
                <textElement>
                    <font isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA[$V{field2_count} > 0 ? "field2" : null]]></textFieldExpression>
            </textField>
        </band>
    </columnHeader>
    <detail>
        <band height="17" splitType="Stretch">
            <property name="com.jaspersoft.studio.unit.height" value="px"/>
            <textField>
                <reportElement x="0" y="0" width="100" height="12" uuid="6f8ce0e1-b4d1-4c3a-ab20-f57dda15fbab">
                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="bf75b6ee-b46c-4aa6-9f57-d15a9c87f716"/>
                    <property name="com.jaspersoft.studio.unit.height" value="px"/>
                </reportElement>
                <textFieldExpression><![CDATA[$F{field1}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="240" y="0" width="100" height="12" uuid="06138904-09f2-4c1b-8218-3982416ebc7e">
                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="bf75b6ee-b46c-4aa6-9f57-d15a9c87f716"/>
                    <property name="com.jaspersoft.studio.unit.height" value="px"/>
                </reportElement>
                <textFieldExpression><![CDATA[$F{field2}]]></textFieldExpression>
            </textField>
        </band>
</detail>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23951958

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档