如何在Jasper报告中添加目录

问题描述 投票:0回答:1

我正在使用 JasperSoft Studio。我正在生成一份报告,其中也有章节和子章节。但所有这些章节和子章节都在子报告中配置。

我如何才能获得所有这些章节和子章节名称以及链接,页码在一页中格式化的目录中,就像文档的标准目录一样?

编辑:移动用户对问题的回答(应该是问题的编辑)

书签出现在 jasperserver 中(在单独的选项卡中),但没有出现在报告中。在TOC中所有字段evaluationTime=report。这是我的 TOC jrxml 代码。

<detail>
    <band height="25" splitType="Stretch">
        <property name="local_mesure_unitheight" value="pixel"/>
        <property name="com.jaspersoft.studio.unit.height" value="px"/>
        <printWhenExpression><![CDATA[$F{level} == 1]]></printWhenExpression>
        <textField evaluationTime="Report" hyperlinkType="LocalAnchor">
            <reportElement style="HeadingLabel1" x="0" y="5" width="470" height="20" uuid="379fcff2-021d-4761-a89a-eeb772723b1b">
                <property name="local_mesure_unitheight" value="pixel"/>
                <property name="com.jaspersoft.studio.unit.height" value="px"/>
                <property name="local_mesure_unity" value="pixel"/>
                <property name="com.jaspersoft.studio.unit.y" value="px"/>
            </reportElement>
            <textFieldExpression><![CDATA[$F{label}]]></textFieldExpression>
            <hyperlinkAnchorExpression><![CDATA[$F{label}]]></hyperlinkAnchorExpression>
        </textField>
        <textField evaluationTime="Auto" hyperlinkType="LocalAnchor">
            <reportElement style="HeadingIndex1" x="470" y="5" width="45" height="20" uuid="a31e80f3-f1fa-4643-adbe-77a61c7b9051">
                <property name="local_mesure_unitheight" value="pixel"/>
                <property name="com.jaspersoft.studio.unit.height" value="px"/>
                <property name="com.jaspersoft.studio.unit.y" value="px"/>
            </reportElement>
            <textElement textAlignment="Right" verticalAlignment="Bottom"/>
            <textFieldExpression><![CDATA[$V{PAGE_NUMBER} + $F{pageIndex} + 1]]></textFieldExpression>
            <hyperlinkAnchorExpression><![CDATA[$F{label}]]></hyperlinkAnchorExpression>
        </textField>
    </band>
    <band height="25" splitType="Stretch">
        <property name="local_mesure_unitheight" value="pixel"/>
        <property name="com.jaspersoft.studio.unit.height" value="px"/>
        <printWhenExpression><![CDATA[$F{level} == 2]]></printWhenExpression>
        <textField evaluationTime="Report" hyperlinkType="LocalAnchor">
            <reportElement style="HeadingLabel2" x="40" y="5" width="430" height="20" uuid="379fcff2-021d-4761-a89a-eeb772723b1b">
                <property name="local_mesure_unitheight" value="pixel"/>
                <property name="com.jaspersoft.studio.unit.height" value="px"/>
                <property name="com.jaspersoft.studio.unit.y" value="px"/>
            </reportElement>
            <textFieldExpression><![CDATA[$F{label}]]></textFieldExpression>
            <hyperlinkAnchorExpression><![CDATA[$F{label}]]></hyperlinkAnchorExpression>
        </textField>
        <textField evaluationTime="Auto" hyperlinkType="LocalAnchor">
            <reportElement style="HeadingIndex2" x="470" y="5" width="45" height="20" uuid="a31e80f3-f1fa-4643-adbe-77a61c7b9051">
                <property name="local_mesure_unitheight" value="pixel"/>
                <property name="com.jaspersoft.studio.unit.height" value="px"/>
                <property name="com.jaspersoft.studio.unit.y" value="px"/>
            </reportElement>
            <textElement textAlignment="Right" verticalAlignment="Bottom"/>
            <textFieldExpression><![CDATA[$V{PAGE_NUMBER} + $F{pageIndex} + 1]]></textFieldExpression>
            <hyperlinkAnchorExpression><![CDATA[$F{label}]]></hyperlinkAnchorExpression>
        </textField>
        <textField evaluationTime="Report" hyperlinkType="LocalAnchor">
            <reportElement style="HeadingLabel2" x="20" y="5" width="20" height="20" uuid="ae12cafd-22e8-45ae-a1a7-8e00a8208cf0">
                <property name="local_mesure_unitheight" value="pixel"/>
                <property name="com.jaspersoft.studio.unit.height" value="px"/>
                <property name="local_mesure_unity" value="pixel"/>
                <property name="com.jaspersoft.studio.unit.y" value="px"/>
            </reportElement>
            <textFieldExpression><![CDATA[$V{level2Index} + "."]]></textFieldExpression>
            <hyperlinkAnchorExpression><![CDATA[$F{label}]]></hyperlinkAnchorExpression>
        </textField>
    </band>
    <band height="15" splitType="Stretch">
        <property name="local_mesure_unitheight" value="pixel"/>
        <property name="com.jaspersoft.studio.unit.height" value="px"/>
        <printWhenExpression><![CDATA[$F{level} == 3]]></printWhenExpression>
        <textField evaluationTime="Report" hyperlinkType="LocalAnchor">
            <reportElement style="HeadingLabel3" x="40" y="0" width="430" height="15" uuid="379fcff2-021d-4761-a89a-eeb772723b1b">
                <property name="local_mesure_unitheight" value="pixel"/>
                <property name="com.jaspersoft.studio.unit.height" value="px"/>
            </reportElement>
            <textFieldExpression><![CDATA[$F{label}]]></textFieldExpression>
            <hyperlinkAnchorExpression><![CDATA[$F{label}]]></hyperlinkAnchorExpression>
        </textField>
        <textField evaluationTime="Auto" hyperlinkType="LocalAnchor">
            <reportElement style="HeadingIndex3" x="470" y="0" width="45" height="15" uuid="a31e80f3-f1fa-4643-adbe-77a61c7b9051">
                <property name="local_mesure_unitheight" value="pixel"/>
                <property name="com.jaspersoft.studio.unit.height" value="px"/>
            </reportElement>
            <textElement textAlignment="Right" verticalAlignment="Bottom"/>
            <textFieldExpression><![CDATA[$V{PAGE_NUMBER} + $F{pageIndex} + 1]]></textFieldExpression>
            <hyperlinkAnchorExpression><![CDATA[$F{label}]]></hyperlinkAnchorExpression>
        </textField>
    </band>
</detail>

编辑:这是我的主要报告 jrxml。

<property name="com.jaspersoft.studio.data.defaultdataadapter" value="TCD"/>
<property name="net.sf.jasperreports.print.create.bookmarks" value="true"/>
<property name="com.jaspersoft.studio.book.group.cover.header" value="Cover and Table of Contents"/>
<property name="com.jaspersoft.studio.book.group.cover.footer" value="Backcover"/>
<property name="ireport.jasperserver.url" value="http://localhost:8080/jasperserver/"/>
<property name="ireport.jasperserver.user" value="jasperadmin"/>
<property name="ireport.jasperserver.report.resource" value="/reports/TCD_book_page_files/main_jrxml"/>
<property name="ireport.jasperserver.reportUnit" value="/reports/TCD_book_page"/>
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<queryString>
    <![CDATA[SELECT 1 NO FROM DUAL]]>
</queryString>
<field name="NO" class="java.lang.Integer"/>
<group name="cover">
    <groupHeader>
        <part evaluationTime="Report" uuid="56ab525c-754f-4f48-a52c-7cc23934be3d">
            <property name="net.sf.jasperreports.bookmarks.data.source.parameter" value="REPORT_DATA_SOURCE"/>
            <p:subreportPart xmlns:p="http://jasperreports.sourceforge.net/jasperreports/parts" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/parts http://jasperreports.sourceforge.net/xsd/parts.xsd">
                <subreportExpression><![CDATA["TCD_book_page_toc.jasper"]]></subreportExpression>
            </p:subreportPart>
        </part>
    </groupHeader>
</group>
<detail>
    <part uuid="5196d1c8-d060-450f-b9f5-9089918b7389">
        <p:subreportPart xmlns:p="http://jasperreports.sourceforge.net/jasperreports/parts" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/parts http://jasperreports.sourceforge.net/xsd/parts.xsd">
            <subreportParameter name="REPORT_CONNECTION">
                <subreportParameterExpression><![CDATA[$P{REPORT_CONNECTION}]]></subreportParameterExpression>
            </subreportParameter>
            <subreportExpression><![CDATA["TCD_Page.jrxml"]]></subreportExpression>
        </p:subreportPart>
    </part>
</detail>

jasper-reports
1个回答
0
投票

即使您的子报表中有书签,https://jasperreports.sourceforge.net/sample.reference/tableofcontents/README.html也可以工作。 (在示例中,它们位于子报告中)。

一些重要通知:

主报告应设置 net.sf.jasperreports.print.create.bookmarks 以便在报告生成时收集书签。

目录部分需要在其他报告之后进行评估 部分;如果该部分要打印在文档的开头 它应该有报告评估(并且后续部分不应该有 相同评价)。

如果您不想使用 jasper reports 的此功能,您需要生成自己的 scriplet 来收集数据,请参阅示例:

如何在 ireport-jasperreports 中构建目录

© www.soinside.com 2019 - 2024. All rights reserved.