JasperReport - wrap text to show long text in textfield

前端 未结 2 1865
不知归路
不知归路 2020-12-01 03:57

I am using jasper report as reporting tool in my application. And I am wondering how can i wrap the long text by expanding the reportElement dynamically into ve

相关标签:
2条回答
  • 2020-12-01 04:00

    I found the answer myself :

    I did some extra research about the properties of textField and rectangle components. And found that I need to set the following properties.

    For rectangle :

            <rectangle>
                <reportElement stretchType="RelativeToBandHeight" ... />
            </rectangle>
    

    For textField :

            <textField isStretchWithOverflow="true">
                ...
            </textField>
    

    Output as expected :

    enter image description here

    The <detail> ...</detail> section after correction :

    <detail>
            <band height="21" splitType="Stretch">
                <rectangle>
                    <reportElement stretchType="RelativeToBandHeight" x="0" y="0" width="88" height="21"/>
                </rectangle>
                <textField isStretchWithOverflow="true">
                    <reportElement x="2" y="0" width="84" height="21"/>
                    <textElement verticalAlignment="Middle"/>
                    <textFieldExpression><![CDATA[$F{personName}]]></textFieldExpression>
                </textField>
                <rectangle>
                    <reportElement stretchType="RelativeToBandHeight" x="88" y="0" width="122" height="21"/>
                </rectangle>
                <textField isStretchWithOverflow="true">
                    <reportElement x="90" y="0" width="118" height="21"/>
                    <textElement verticalAlignment="Middle"/>
                    <textFieldExpression><![CDATA[$F{address}]]></textFieldExpression>
                </textField>
            </band>
        </detail>
    

    UPDATE

    You can also set property net.sf.jasperreports.print.keep.full.text to true to achieve that across your all reports.

    0 讨论(0)
  • 2020-12-01 04:21

    Also you can make the truncation elegant by using the following properties set to the textfield. Check this sample

    net.sf.jasperreports.text.truncate.at.char 
    net.sf.jasperreports.text.truncate.suffix 
    net.sf.jasperreports.print.keep.full.text 
    
    0 讨论(0)
提交回复
热议问题