gpt4 book ai didi

jasper-reports - Jasper 报告多行边框底部

转载 作者:行者123 更新时间:2023-12-04 08:27:42 28 4
gpt4 key购买 nike

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

例如:

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>

最佳答案

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

首先,我定义一个 java.util.List 变量,用于在换行符上分割您的字符串。我没有使用 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>

结果

Split result

关于jasper-reports - Jasper 报告多行边框底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34749897/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com