【问题标题】:Jasper report border bottom for multiple linesJasper 报告多行边框底部
【发布时间】:2016-03-21 19:35:19
【问题描述】:

我想为一个多行显示其内容的文本字段绘制一个虚线底部边框。

例如:

Address: 104th Street,
         - - - - - - - - - - -- - - - - - - -- - - - - -
         Beside Market Area
         - - - - - -- - - - - -- - - - - -- - - - -- - - 
         Illinois,617273
         - - - - - -- - - - - -- - - - - -- - - - -- - - 

目前,当我将边框底部设置为文本字段时,它以这种方式显示

Address: 104th Street,
         Beside Market Area
         Illinois,617273
         - - - - - -- - - - - -- - - - - -- - - - -- - - 

请帮助我了解如何为多行文本的每行设置边框底部

在下面找到我的 jxml 代码

<?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="Blank_A4_1" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="ab424386-3966-4b59-9892-31b3fdb6c498">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="Mysql Adapter "/>
    <property name="com.jaspersoft.studio.data.sql.tables" value=""/>
    <queryString>
        <![CDATA[Select "104th Street,\n Beside Market Area\n Illinois,617273" as address from dual]]>
    </queryString>
    <field name="address" class="java.lang.String"/>
    <title>
        <band height="79" splitType="Stretch"/>
    </title>
    <detail>
        <band height="125" splitType="Stretch">
            <staticText>
                <reportElement x="10" y="30" width="122" height="30" uuid="b2d1bb4b-38b0-47e9-8da8-5ce6a31c98a8"/>
                <textElement textAlignment="Right" verticalAlignment="Middle">
                    <font size="20"/>
                </textElement>
                <text><![CDATA[Address]]></text>
            </staticText>
            <textField isStretchWithOverflow="true">
                <reportElement x="150" y="30" width="390" height="30" uuid="40d76fd8-76d0-4d37-8bc7-bb4e48749df2"/>
                <box leftPadding="10">
                    <bottomPen lineWidth="1.0" lineStyle="Dashed"/>
                </box>
                <textElement verticalAlignment="Middle"/>
                <textFieldExpression><![CDATA[$F{address}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
    <pageFooter>
        <band height="54" splitType="Stretch"/>
    </pageFooter>
</jasperReport>

【问题讨论】:

  • 请附上一些相关的 jrxml 代码,以便我们看到你现在在做什么...stretchWithOverFlow??
  • 使用 JRXML 代码更新

标签: jasper-reports


【解决方案1】:

如果您设法在查询中的单独字段中分手,@mbmast 解决方案当然很好,但为了回答您的问题,我将向您展示您可以在 jasper 报告中做什么“疯狂的事情”。

首先我定义了一个java.util.List 变量split 你在换行符上的字符串。我没有使用String[],因为这会破坏报告 IDE

<variable name="addressArray" class="java.util.List">
    <variableExpression><![CDATA[Arrays.asList($F{address}.split("\\n"))]]></variableExpression>
</variable>

现在我们可以添加textField 并获得我们想要显示的位置。为了避免 ArrayIndexOutOfBoundsException 使用 printWhenExpression(为了证明这一点,我在示例中放置了 4 个 textField

示例代码

<?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="Blank_A4_1" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="ab424386-3966-4b59-9892-31b3fdb6c498">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="Mysql Adapter "/>
    <property name="com.jaspersoft.studio.data.sql.tables" value=""/>
    <queryString>
        <![CDATA[Select "104th Street,\n Beside Market Area\n Illinois,617273" as address from dual]]>
    </queryString>
    <field name="address" class="java.lang.String"/>
    <variable name="addressArray" class="java.util.List">
        <variableExpression><![CDATA[Arrays.asList($F{address}.split("\\n"))]]></variableExpression>
    </variable>
    <title>
        <band height="79" splitType="Stretch"/>
    </title>
    <detail>
        <band height="154" splitType="Stretch">
            <staticText>
                <reportElement x="10" y="30" width="122" height="30" uuid="b2d1bb4b-38b0-47e9-8da8-5ce6a31c98a8"/>
                <textElement textAlignment="Right" verticalAlignment="Middle">
                    <font size="20"/>
                </textElement>
                <text><![CDATA[Address]]></text>
            </staticText>
            <textField isStretchWithOverflow="true">
                <reportElement x="150" y="30" width="390" height="30" isRemoveLineWhenBlank="true" uuid="40d76fd8-76d0-4d37-8bc7-bb4e48749df2">
                    <printWhenExpression><![CDATA[$V{addressArray}.size()>0]]></printWhenExpression>
                </reportElement>
                <box leftPadding="10">
                    <bottomPen lineWidth="1.0" lineStyle="Dashed"/>
                </box>
                <textElement verticalAlignment="Middle"/>
                <textFieldExpression><![CDATA[$V{addressArray}.get(0)]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true">
                <reportElement positionType="Float" x="150" y="60" width="390" height="30" isRemoveLineWhenBlank="true" uuid="fcba83d9-5a57-45b4-b015-b23a12043784">
                    <printWhenExpression><![CDATA[$V{addressArray}.size()>1]]></printWhenExpression>
                </reportElement>
                <box leftPadding="10">
                    <bottomPen lineWidth="1.0" lineStyle="Dashed"/>
                </box>
                <textElement verticalAlignment="Middle"/>
                <textFieldExpression><![CDATA[$V{addressArray}.get(1)]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true">
                <reportElement positionType="Float" x="150" y="90" width="390" height="30" isRemoveLineWhenBlank="true" uuid="d39e756a-7e2b-409d-a423-2a8df5dd7378">
                    <printWhenExpression><![CDATA[$V{addressArray}.size()>2]]></printWhenExpression>
                </reportElement>
                <box leftPadding="10">
                    <bottomPen lineWidth="1.0" lineStyle="Dashed"/>
                </box>
                <textElement verticalAlignment="Middle"/>
                <textFieldExpression><![CDATA[$V{addressArray}.get(2)]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true">
                <reportElement positionType="Float" x="150" y="120" width="390" height="30" isRemoveLineWhenBlank="true" uuid="12fe3b4f-2b13-4b3a-98ae-adc834f89bc1">
                    <printWhenExpression><![CDATA[$V{addressArray}.size()>3]]></printWhenExpression>
                </reportElement>
                <box leftPadding="10">
                    <bottomPen lineWidth="1.0" lineStyle="Dashed"/>
                </box>
                <textElement verticalAlignment="Middle"/>
                <textFieldExpression><![CDATA[$V{addressArray}.get(3)]]></textFieldExpression>
            </textField>
        </band>
    </detail>
    <pageFooter>
        <band height="54" splitType="Stretch"/>
    </pageFooter>
</jasperReport>

结果

【讨论】:

    【解决方案2】:

    将您的地址分成单独的字段(即 address-line-1address-line2 等,而不是 address 中的所有内容)。然后使用&lt;printWhenExpression&gt; 有条件地包含该行(如果它不是空白或空)。对于要包含的内容(即满足您的条件),您可以包含一个嵌套的 &lt;staticText&gt; 字段作为分隔线。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多