“合理的" jaspersoft报表中textField和staticText的属性不起作用 [英] "justified" property of textField and staticText is not working in jaspersoft report

查看:131
本文介绍了“合理的" jaspersoft报表中textField和staticText的属性不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在textField和staticText中添加设置文本,因为它将在jasper报告中以相等的空间分割.

I want add set text in textField and staticText as it will divide in equal space in jasper report.

文本应该像下面的图片一样分布.

Text should be distributed like below image.

将textAlignment设置为"Justified",但无效.

Setting textAlignment to "Justified", but it didn't work.

有人可以建议我解决这个问题的方法吗?

Can someone suggest me the solution for this?

我必须在jasper报告中执行此操作,并在PDF文件中生成报告.

I have to do it in jasper report and generate an report in PDF file.

<staticText>
    <reportElement x="52" y="34" width="135" height="20" uuid="44eed122-c07e-42d0-b696-a6ad54b759a4"/>
    <textElement textAlignment="Justified" verticalAlignment="Middle" rotation="None">
        <font fontName="Serif" size="12"/>
    </textElement>
    <text><![CDATA[Welcome]]></text>
</staticText>

文本应该像PDF报告中的波纹管文本那样分布.

Text should be distributed like bellow text in PDF report.

推荐答案

正义-为了使连续文本行的左右两端对齐,单词之间以及字形或字母之间的空格将被拉伸或压缩.使用对齐方式时,习惯上通过根据语言方向简单地向左或向右对齐来单独处理段落的最后一行.

Justification - the spaces between words and between glyphs or letters are stretched or compressed in order to align both the left and right ends of consecutive lines of text. When using justification, it is customary to treat the last line of a paragraph separately by simply left or right aligning it, depending on the language direction.

因此,您需要文本行来查看textAlignment="Left"textAlignment="Justified"值之间的差异.我猜想对齐 textAlignment="Justified"可以正常工作,但是可以处理文本作为段落的最后一行".如果将长文本放在staticText中,则不会出现任何问题(v6.9.0.).请参见下图.

So you need lines of text to see the difference between textAlignment="Left" and textAlignment="Justified" values. I guess the alignment textAlignment="Justified" works properly but it treats the text as "the last line of a paragraph". If you put long text in staticText you will have no troubles (v6.9.0.). See the image below.

解决方法可能是这样的:

The workaround could be something just like this:

  1. 创建tabSet变量

<variable name="tabSet" class="java.lang.String">
    <variableExpression><![CDATA["&#09;&#09;&#09;&#09;&#09;"]]></variableExpression>
    <initialValueExpression><![CDATA["&#09;&#09;&#09;&#09;&#09;"]]></initialValueExpression></variableExpression>
</variable>

  1. 将变量添加到需要证明其正确性的任何表达式中,包括最后\第一行

<textFieldExpression><![CDATA["Lorem ipsum dolor sit amet"+$V{tabSet}]]></textFieldExpression>

  1. 设置对齐方式和标记

<textElement textAlignment="Justified" markup="html"/>

下面的完整示例:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.9.0.final using JasperReports Library version 6.9.0-cb8f9004be492ccc537180b49c026951f4220bf3  -->
<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="report3" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="00216f45-7b94-4847-94ea-7ea4f1508a6e">
    <scriptlet name="DynTable" class="net.sf.jasperreports.engine.JRDefaultScriptlet">
        <scriptletDescription><![CDATA[]]></scriptletDescription>
    </scriptlet>
    <variable name="tabSet" class="java.lang.String">
        <variableExpression><![CDATA["&#09;&#09;&#09;&#09;&#09;"]]></variableExpression>
        <initialValueExpression><![CDATA["&#09;&#09;&#09;&#09;&#09;"]]></initialValueExpression>
    </variable>
    <detail>
        <band height="560" splitType="Stretch">
            <textField>
                <reportElement x="0" y="0" width="550" height="20" uuid="803f5f42-1d88-4da6-973e-bb70e6e99388"/>
                <textElement textAlignment="Center">
                    <font isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA["Justified"]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true">
                <reportElement x="0" y="20" width="550" height="20" uuid="803f5f42-1d88-4da6-973e-bb70e6e99388"/>
                <textElement textAlignment="Justified" verticalAlignment="Middle" markup="styled"/>
                <textFieldExpression><![CDATA["Lorem ipsum dolor sit amet"]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="0" y="40" width="550" height="20" uuid="1132e9a7-8b30-4167-94ce-a013480dca9d"/>
                <textElement textAlignment="Center">
                    <font isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA["Left"]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="0" y="60" width="550" height="20" uuid="803f5f42-1d88-4da6-973e-bb70e6e99388"/>
                <textElement textAlignment="Left" verticalAlignment="Justified"/>
                <textFieldExpression><![CDATA["Lorem ipsum dolor sit amet"]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="0" y="80" width="550" height="20" uuid="bc341f2a-916e-4391-90dc-8b68684d2c6c"/>
                <textElement textAlignment="Center">
                    <font isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA["Justified"]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true">
                <reportElement x="0" y="100" width="550" height="60" uuid="803f5f42-1d88-4da6-973e-bb70e6e99388"/>
                <textElement textAlignment="Justified" verticalAlignment="Justified" markup="none"/>
                <textFieldExpression><![CDATA["Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="0" y="160" width="550" height="20" uuid="8472fd7d-b77c-46bf-9a11-b5f4cd1fff78"/>
                <textElement textAlignment="Center">
                    <font isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA["Left"]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="0" y="180" width="550" height="60" uuid="803f5f42-1d88-4da6-973e-bb70e6e99388"/>
                <textElement textAlignment="Left" verticalAlignment="Top"/>
                <textFieldExpression><![CDATA["Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="0" y="240" width="550" height="20" uuid="8da01066-6dc6-4551-8530-2ac179fab340"/>
                <textElement textAlignment="Center">
                    <font isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA["Workaround"]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="0" y="260" width="550" height="20" uuid="931c0377-e69d-41e9-8c0e-eec6b53d14d1"/>
                <box>
                    <topPen lineWidth="1.0"/>
                    <leftPen lineWidth="1.0"/>
                    <bottomPen lineWidth="1.0"/>
                    <rightPen lineWidth="1.0"/>
                </box>
                <textElement textAlignment="Justified" markup="html"/>
                <textFieldExpression><![CDATA["Lorem"+$V{tabSet}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="0" y="280" width="550" height="20" uuid="aa466b7b-c67b-4cf7-bb52-09d52fceedf6"/>
                <box>
                    <topPen lineWidth="1.0"/>
                    <leftPen lineWidth="1.0"/>
                    <bottomPen lineWidth="1.0"/>
                    <rightPen lineWidth="1.0"/>
                </box>
                <textElement textAlignment="Justified" markup="html"/>
                <textFieldExpression><![CDATA["Lorem ipsum"+$V{tabSet}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="0" y="300" width="550" height="20" uuid="e6cb9bd0-80b6-4138-9e58-803caf5b9c54"/>
                <box>
                    <topPen lineWidth="1.0"/>
                    <leftPen lineWidth="1.0"/>
                    <bottomPen lineWidth="1.0"/>
                    <rightPen lineWidth="1.0"/>
                </box>
                <textElement textAlignment="Justified" markup="html"/>
                <textFieldExpression><![CDATA["Lorem ipsum dolor"+$V{tabSet}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="1" y="320" width="550" height="20" uuid="113a944e-b09b-419e-abf9-06b76959731d"/>
                <box>
                    <topPen lineWidth="1.0"/>
                    <leftPen lineWidth="1.0"/>
                    <bottomPen lineWidth="1.0"/>
                    <rightPen lineWidth="1.0"/>
                </box>
                <textElement textAlignment="Justified" markup="html"/>
                <textFieldExpression><![CDATA["Lorem ipsum dolor sit"+$V{tabSet}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="0" y="340" width="550" height="20" uuid="920883bb-cd3a-4a26-99e4-ad0a5415033f"/>
                <box>
                    <topPen lineWidth="1.0"/>
                    <leftPen lineWidth="1.0"/>
                    <bottomPen lineWidth="1.0"/>
                    <rightPen lineWidth="1.0"/>
                </box>
                <textElement textAlignment="Justified" markup="html"/>
                <textFieldExpression><![CDATA["Lorem ipsum dolor sit amet"+$V{tabSet}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
</jasperReport>

这篇关于“合理的" jaspersoft报表中textField和staticText的属性不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆