首页 文章

Jasper Reports - 水平对齐动态文本字段及其标签

提问于
浏览
16

我正在使用Jasper报告5.2,iReport 5.2并以RTF和PDF格式导出报告 .

在我的报告中,我想添加几个文本字段以及水平对齐的(静态文本)标签

Name:  $F{name}
          Age:  $F{age}
Date of Birth:  $F{dateOfBirth}

但我无法调整它们 . 这就是我试过的

  • Position Type: float(适用于所有静态文本和字段)

  • Stretch Type: 无拉伸(适用于所有静态文本和字段)

  • Stretch With Overflow: True(适用于所有动态文本字段)

图像显示了我得到的和我想要的东西 . 此外,我的文本字段的内容是动态的,即内容大小可能会有所不同 .
enter image description here

我已经阅读了很多论坛,但找不到解决方案,请提出建议 .

谢谢

4 回答

  • 2

    它可以通过容器 - Frame元素轻松完成 .

    您应该将具有位置类型的框架设置为 Float ,并将staticText(label)和textField都添加到它们中 .

    对于textField,我将Position Type设置为 Float ,将Stretch With Overlfow设置为 true .

    样本

    jrxml文件:

    <?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="textfields_allign" language="groovy" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="d855bf18-5e9b-4060-8caa-3fdd08abce3b">
        <parameter name="name" class="java.lang.String"/>
        <parameter name="id" class="java.lang.String"/>
        <parameter name="date" class="java.lang.String"/>
        <title>
            <band height="69" splitType="Stretch">
                <frame>
                    <reportElement uuid="314bfd5b-7b0a-42f4-aca3-e61f0283f126" positionType="Float" x="213" y="1" width="243" height="20"/>
                    <staticText>
                        <reportElement uuid="e07201bb-a677-4dc9-a332-f94e6eca2722" positionType="Float" x="0" y="0" width="100" height="20" isPrintWhenDetailOverflows="true"/>
                        <textElement/>
                        <text><![CDATA[Name]]></text>
                    </staticText>
                    <textField isStretchWithOverflow="true">
                        <reportElement uuid="66c93a44-9015-4ae9-bf05-b68b2420f3ef" positionType="Float" x="121" y="0" width="100" height="20" isPrintWhenDetailOverflows="true"/>
                        <textElement/>
                        <textFieldExpression><![CDATA[$P{name}]]></textFieldExpression>
                    </textField>
                </frame>
                <frame>
                    <reportElement uuid="8311a483-955e-4280-a9ac-513d7d34495b" positionType="Float" x="213" y="21" width="243" height="20"/>
                    <staticText>
                        <reportElement uuid="da404b4e-7908-40ae-8e1b-38e19d9ddc7f" positionType="Float" x="0" y="0" width="100" height="20" isPrintWhenDetailOverflows="true"/>
                        <textElement/>
                        <text><![CDATA[ID]]></text>
                    </staticText>
                    <textField isStretchWithOverflow="true">
                        <reportElement uuid="e0e312e8-cd2f-48af-8ae8-df95c6195488" positionType="Float" x="121" y="0" width="100" height="20" isPrintWhenDetailOverflows="true"/>
                        <textElement/>
                        <textFieldExpression><![CDATA[$P{id}]]></textFieldExpression>
                    </textField>
                </frame>
                <frame>
                    <reportElement uuid="8ff2baf9-b0ec-4c8a-b54a-9edd08b200cc" positionType="Float" x="213" y="41" width="243" height="20"/>
                    <staticText>
                        <reportElement uuid="b8d97db0-250a-43c8-a2f3-2fa3668c5d15" positionType="Float" x="0" y="0" width="100" height="20" isPrintWhenDetailOverflows="true"/>
                        <textElement/>
                        <text><![CDATA[Date]]></text>
                    </staticText>
                    <textField isStretchWithOverflow="true">
                        <reportElement uuid="4daa4d17-28be-4ac8-8e1e-2efbeec5f690" positionType="Float" x="121" y="0" width="100" height="20" isPrintWhenDetailOverflows="true"/>
                        <textElement/>
                        <textFieldExpression><![CDATA[$P{date}]]></textFieldExpression>
                    </textField>
                </frame>
            </band>
        </title>
    </jasperReport>
    

    该报告在iReport中的设计:

    enter image description here

    结果将是(通过iReport预览):

    enter image description here

  • 0

    要完成Alex K的解决方案:使用Jaspersoft Studio,不要忘记将静态文本“拉伸类型”的属性设置为“相对于最高对象” .

  • 3

    在Jasper Reports 3.6及更高版本(包括5.2)中,有一个使用多个细节带的工具 . 您可以将 Name 的前两个块和"Sally Admison ..."的文本放在第一个波段中 . 下面是你的 Patient ID 和"1234567890Blah..."及以下,这将是 Date of Birth 的另一个细节乐队 . 这将为您提供所需的结果 .

    请不要参考我的帖子here,因为这是旧版本的Jasper Reports . 那个版本不允许你使用多个乐队,我不得不忍受一个单一的细节乐队 . 5.2不是这种情况 . 您可以享受多个细节乐队的乐趣 . 请享用!

  • 30

    只需增加详细信息窗格的宽度,即为我排序对齐问题 .

相关问题