1

我需要在 JasperReports 中创建目录。我已经实现了这一点,但不能对 TOC 中的行做任何事情。

目前它们有一个静态宽度:

Chapter 1          ........ 2
Long Chapter Name  ........ 3
End                ........ 4

我想将虚线拉伸到章节名称的宽度。像这儿:

Chapter 1 ................. 2
Long Chapter Name ......... 3
End ....................... 4

我怎样才能做到这一点?JR 中是否有一些“填充”功能,或者我应该为此任务创建脚本?谢谢!

PS 我正在使用 jasper 报告 5.0.1

4

1 回答 1

1

这不是一个非常整洁的方法,但我会在您的文本框中绘制许多点并使用框架隐藏结尾以允许写入页码。

<?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="table of content" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="df5894b6-0e62-4082-bdb8-3f0a1b26a2f4">
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <queryString>
        <![CDATA[SELECT
     1 AS page,
     'test' AS title
FROM
     "account" account
Union
SELECT
     4 AS page,
     'chapter 2' AS title
FROM
     "account" account
Union
SELECT
     20 AS page,
     'chapter 3: hello' AS title
FROM
     "account" account]]>
    </queryString>
    <field name="page" class="java.lang.Integer"/>
    <field name="title" class="java.lang.String"/>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="20" splitType="Stretch">
            <staticText>
                <reportElement uuid="2e81fd32-3b8d-4b98-b96d-6409afb8d16f" x="0" y="0" width="555" height="20"/>
                <textElement>
                    <font isBold="true" isStrikeThrough="false"/>
                </textElement>
                <text><![CDATA[Table of content]]></text>
            </staticText>
        </band>
    </title>
    <columnHeader>
        <band splitType="Stretch"/>
    </columnHeader>
    <detail>
        <band height="20" splitType="Stretch">
            <textField>
                <reportElement uuid="c8707508-946a-48ae-ae75-61810003e1db" x="0" y="0" width="555" height="20"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{title}+"  .............................................................................................................................."]]></textFieldExpression>
            </textField>
            <frame>
                <reportElement uuid="4040d203-6b49-4da2-8bcf-f3d6d48c7fd7" mode="Opaque" x="341" y="0" width="214" height="20"/>
            </frame>
            <textField>
                <reportElement uuid="472f8f95-fdea-4cd9-b3a5-a1b9b66a8c44" mode="Opaque" x="321" y="0" width="20" height="20"/>
                <textElement textAlignment="Right"/>
                <textFieldExpression><![CDATA[$F{page}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
</jasperReport>
于 2013-03-12T14:30:59.707 回答