首页 > 解决方案 > 如何在文本字段中强制中断长文本

问题描述

我想强制在文本字段中中断很长的文本。我不在乎文本中是否有空格。如果文本字段宽度太长,我只想让文本出现在下一行。

我试过这个:

            <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                <reportElement key="textField-2" positionType="Float" stretchType="RelativeToTallestObject" x="409" y="170" width="146" height="28">
                    <property name="net.sf.jasperreports.text.save.line.breaks" value="true"/>
                </reportElement>
                <box>
                    <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement>
                    <font fontName="Courier New" size="8"/>
                </textElement>
                <textFieldExpression class="java.lang.String"><![CDATA[$F{customerReference}]]></textFieldExpression>
            </textField>

但它不起作用。我只是在第一个连字符之后切断了文本,其余的文本不显示。

一个示例文本是:

SIN684473 - 403904156/OO0D628902B SIN684473 - 403904156/OO0D628902B

请帮忙。谢谢。

编辑 1:感谢 Alex K,它现在可以在 PDF 中使用。但现在在 Excel 文件中,customerReference 字段为空。但它在 PDF 中不是空的。

请帮忙。谢谢。

标签: jasper-reports

解决方案


推荐阅读