我想为文本字段绘制一个虚线底部边框,以多行显示其内容。
例如:
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>
答案 0 :(得分:3)
如果你设法在查询的单独字段中分手肯定@mbmast解决方案是好的,但是为了回答你的问题,我将向你展示你可以在jasper报告中做什么“疯狂的东西”。
首先,我定义一个java.util.List
变量,在你的换行符上split
为String。我没有使用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>
<强>结果强>
答案 1 :(得分:2)
将您的地址分成不同的字段(例如地址行1 ,地址行2 等,而不是地址中的所有内容)。然后使用<printWhenExpression>
有条件地包含该行(如果它不是空行或null)。对于要包含的那些(即满足您的条件),您可以为分隔线包含嵌套的<staticText>
字段。