20

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

在我的报告中,我想添加一些文本字段及其水平对齐的(静态文本)标签,例如

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

但我无法对齐它们。这是我尝试过的

  • 职位类型:浮动(适用于所有静态文本和字段)
  • 拉伸类型:无拉伸(适用于所有静态文本和字段)
  • 溢出拉伸:真(适用于所有动态文本字段)

图片显示了我得到的和我想要的。此外,我的文本字段的内容是动态的,即内容大小可能会有所不同。 在此处输入图像描述

看了很多论坛都没有找到解决办法,求指教。

谢谢

4

4 回答 4

35

它可以在容器的帮助下轻松完成 -框架元素。

您应该将FramePosition Type设置为Float并将staticText(标签)和textField放入它们。

对于textField,我将Position Type设置为Float the Stretch With Overlfowtrue

样本

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中的报表设计:

在此处输入图像描述

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

在此处输入图像描述

于 2013-09-04T08:36:11.130 回答
4

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

于 2016-04-21T14:18:59.053 回答
3

在 Jasper Reports 3.6 及更高版本(包括 5.2)中,可以使用多个详细信息波段。您可以将名称的前两个块和“Sally Admison ...”的文本放在第一个带中。下面是您的Patient ID和“1234567890Blah...”,下面是另一个带有Date of Birth 的详细信息带。这将为您提供您想要的结果。

不要在这里参考我的帖子,因为这是针对较旧的 3.5 版本的 Jasper Reports。该版本不允许您使用多个乐队,我不得不与一个单一的细节乐队一起生活。这不是 5.2 的情况。您可以享受多个细节带的乐趣。享受!

于 2013-09-04T07:29:22.917 回答
0

只需增加详细信息窗格的宽度,即可为我解决对齐问题。

于 2014-09-11T11:50:08.200 回答