【问题标题】:Displaying a list of staticText elements: how to remove null values?显示静态文本元素列表:如何删除空值?
【发布时间】:2021-12-13 20:05:26
【问题描述】:

我在 JasperReports 报告中有一个静态文本列表,它们显示在另一个下方

A
B
C
D
E

我需要折叠这些元素,以防其中一些没有打印出来。 (这些静态文本是标签,使用print when表达式对应的值为null时不会打印出来)

示例:如果 B 为空,则输出应如下所示......在 B 所在的位置没有任何空格。 (C,D,E 应该向上浮动)

A
C
D
E

我无法使用 Remove Line When BlankPosition Type as Float 等属性使其工作。没有属性 静态文本为空时为空,文本字段也是如此。这个东西适用于文本字段。

我想出的示例代码。如果这个案例有什么问题,请告诉我:

<detail>
        <band height="170" splitType="Stretch">
            <staticText>
                <reportElement uuid="df801bc0-7c70-42c3-bc34-a8d735a96388" positionType="Float" x="88" y="15" width="100" height="20" isRemoveLineWhenBlank="true"/>
                <textElement/>
                <text><![CDATA[A]]></text>
            </staticText>
            <staticText>
                <reportElement uuid="bdeb24d3-74b9-4b93-a2ad-451732e500b5" positionType="Float" x="88" y="35" width="100" height="20" isRemoveLineWhenBlank="true"/>
                <textElement/>
                <text><![CDATA[B]]></text>
            </staticText>
            <staticText>
                <reportElement uuid="e68dc5fd-ed4f-46e0-aa5d-be1edc652aa3" positionType="Float" x="88" y="55" width="100" height="20" isRemoveLineWhenBlank="true"/>
                <textElement/>
                <text><![CDATA[]]></text>
            </staticText>
            <staticText>
                <reportElement uuid="0b7481b2-33cd-4573-84b2-4a6738ca0ee3" positionType="Float" x="88" y="75" width="100" height="20" isRemoveLineWhenBlank="true"/>
                <textElement/>
                <text><![CDATA[D]]></text>
            </staticText>
            <staticText>
                <reportElement uuid="2b45cded-10f3-46b5-a87b-5c844e61b247" positionType="Float" x="88" y="95" width="100" height="20" isRemoveLineWhenBlank="true"/>
                <textElement/>
                <text><![CDATA[E]]></text>
            </staticText>
        </band>
    </detail>

有人解决了这个问题吗?

【问题讨论】:

  • 如果你说的是staticText,为什么要添加这个带有Null值的元素?你能发布 jrxml 文件吗?
  • 正如我所说,“这些静态文本是标签,如果使用 print when expression 对应的值为 null,则不会打印” - 我有一个“标签:值”形式的元素列表,如果值为 null,则不显示标签
  • 你能和我们分享你的 jrxml 吗?这将使诊断问题变得更加容易。
  • 抱歉回复晚了。我添加了一个示例测试用例。

标签: jasper-reports


【解决方案1】:

您应该将 isPrintRepeatedValues 属性值设置为 false 用于具有空字符串的 staticText

jrxml 文件:

<?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="remove_empty_static" language="groovy" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
  <title>
    <band height="170" splitType="Stretch">
      <staticText>
        <reportElement positionType="Float" x="88" y="15" width="100" height="20" isRemoveLineWhenBlank="true"/>
        <textElement/>
        <text><![CDATA[A]]></text>
      </staticText>
      <staticText>
        <reportElement positionType="Float" x="88" y="35" width="100" height="20" isRemoveLineWhenBlank="true"/>
        <textElement/>
        <text><![CDATA[B]]></text>
      </staticText>
      <staticText>
        <reportElement positionType="Float" isPrintRepeatedValues="false" x="88" y="55" width="100" height="20" isRemoveLineWhenBlank="true"/>
        <textElement/>
      </staticText>
      <staticText>
        <reportElement positionType="Float" x="88" y="75" width="100" height="20" isRemoveLineWhenBlank="true"/>
        <textElement/>
        <text><![CDATA[D]]></text>
      </staticText>
      <staticText>
        <reportElement positionType="Float" x="88" y="95" width="100" height="20" isRemoveLineWhenBlank="true"/>
        <textElement/>
        <text><![CDATA[E]]></text>
      </staticText>
    </band>
  </title>
</jasperReport>

结果将是(通过 iReport 中的预览):

我不知道为什么,但它有效:)

注意

我已经用 Java 代码测试了这个示例 - 结果是一样的。

【讨论】:

    【解决方案2】:

    请将每个“标签:值”放在单独的详细信息带中,并在整个详细信息上使用 print if 表达式。

    【讨论】:

      【解决方案3】:

      试试printWhenExpression:

      字段名称(字符串类型):firstName

              <staticText>
                  <reportElement x="60" y="185" width="130" height="20" uuid="6d98f418-7f61-42ca-ac96-aea325e2aad1">
                      <printWhenExpression><![CDATA[$F{firstName} != null]]></printWhenExpression>
                  </reportElement>
                  <text><![CDATA[FirstName:]]></text>
              </staticText>
      
              <textField isBlankWhenNull="true">
                  <reportElement x="265" y="222" width="181" height="20" uuid="4a04a05a-424a-47f1-a9f9-eecc9c7120c1">
                      <printWhenExpression><![CDATA[$F{firstName} != null]]></printWhenExpression>
                  </reportElement>
                  <textFieldExpression><![CDATA[$F{firstName}]]></textFieldExpression>
              </textField>
      

      用于显示列表

              <textField isBlankWhenNull="true">
                  <reportElement x="0" y="11" width="545" height="17" uuid="8f1b435d-40f4-4e59-a357-b3c2fcc38811">
                  <printWhenExpression><![CDATA[$F{_THIS} != null]]></printWhenExpression>
                  </reportElement>
                  <textFieldExpression><![CDATA[$F{_THIS}]]></textFieldExpression>
              </textField>
      

      【讨论】:

        猜你喜欢
        • 2019-04-06
        • 1970-01-01
        • 2020-11-28
        • 2012-01-23
        • 2013-09-26
        • 2020-03-14
        • 1970-01-01
        • 2013-05-22
        • 2013-10-28
        相关资源
        最近更新 更多