如何在Jasper报告中添加内容表

时间:2015-12-08 13:07:53

标签: jasper-reports

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

如何将所有这些章节和子章节名称与链接,页码在一页内容格式化的内容表格中,如文档内容的标准表格一起获取?

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

书签以jasperserver(在单独的标签中)出现,但未出现在报告中。在TOC中,所有字段评估时间=报告。这是我的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>

1 个答案:

答案 0 :(得分:0)

即使您的子报告中有书签,http://jasperreports.sourceforge.net/sample.reference/tableofcontents/也能正常工作。 (例如,他们在子报告中)。

一些重要的通知:

  

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

     

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

如果您不想使用jasper报告的此功能,则需要生成自己的scriplet来收集数据,例如:

how-can-i-build-a-table-of-contents-in-ireport-jasperreports