2013-03-12 194 views
1

我需要在JasperReports中創建目錄。 我已經實現了這一點,但不能做任何TOC中的行。動態更改元素的寬度

目前,他們有一個靜態的寬度:

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

我想舒展虛線的章節名稱的寬度。像這裏:

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

我該怎麼做? JR中是否有一些「填充」功能,或者我應該爲此任務創建scriptlet嗎?謝謝!

P.S.我使用jasper報告5.0.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> 
+0

很好的破解。我一定會使用它。但我擔心我無法爲段落定製線條。而當它裁剪點時,它看起來不太好。 – 2013-03-12 14:54:12