0

我在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等属性使其工作。静态文本为Null 时没有属性Blank ,就像文本字段一样。这个东西适用于文本字段。

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

<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>

有没有人解决过这个问题?

4

3 回答 3

1

对于空字符串的staticText ,您应该将isPrintRepeatedValues属性值设置为false 。

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代码测试了这个示例——结果是一样的。

于 2013-09-28T15:00:40.427 回答
0

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

于 2013-09-27T06:28:58.920 回答
0

尝试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>
于 2018-01-22T13:13:29.757 回答