Jasper Book Docx导出中的内容导航表

时间:2017-07-25 12:03:06

标签: jasper-reports

我正在生成一本带有目录的jasper书,需要将其导出为DOCx。问题是当我点击TOC中的第一级书签时,没有任何反应。当我点击TOC中的任何第二级标签时,Jasper跳转到封面页(在PDF导出中单击第二级标签跳转到报告中的右侧锚)。我有锚点级别1和2,链接目标是自我类型无。 TOC JRXML

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.4.0.final using JasperReports Library version 6.4.1  -->
<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="TocReport">
<property name="com.jaspersoft.studio.data.defaultdataadapter"     value="dbOne"/>
<property name="com.jaspersoft.studio.unit." value="cm"/>
<property name="net.sf.jasperreports.print.create.bookmarks" value="false"/>
<template><![CDATA[$P{resourcePath}+"Berichtsformatvorlagen.jrtx"]]>   </template>
<parameter name="resourcePath" class="java.lang.String" isForPrompting="false">
    <defaultValueExpression><![CDATA[""]]></defaultValueExpression>
</parameter>
<parameter name="Stand" class="java.lang.String" isForPrompting="false"/>
<parameter name="ErfassungsJahr" class="java.lang.String" isForPrompting="false"/>
<queryString>
    <![CDATA[]]>
</queryString>
<field name="level" class="java.lang.Integer"/>
<field name="label" class="java.lang.String"/>
<field name="pageIndex" class="java.lang.Integer"/>
<variable name="level2Index" class="java.lang.Integer">
    <variableExpression><![CDATA[$F{level} == 1 ? 0 : ($F{level} == 2 ? ($V{level2Index} + 1) : $V{level2Index})]]></variableExpression>
</variable>
<background>
    <band splitType="Stretch"/>
</background>
<pageHeader>
    <band height="50">
        <textField>
            <reportElement style="Formatvorlage Standard (kleiner) + 9 Pt." x="0" y="0" width="133" height="30" uuid="d0084fee-c683-41f4-b554-e86d94ed78e5"/>
            <textFieldExpression><![CDATA["QA Indicator"]]></textFieldExpression>
        </textField>
    </band>
</pageHeader>
<columnHeader>
    <band height="50">
        <textField>
            <reportElement x="0" y="1" width="469" height="49" forecolor="#000000" uuid="24731f07-d115-4be4-a22c-aa9a4c3fc786">
                <property name="local_mesure_unitwidth" value="pixel"/>
                <property name="com.jaspersoft.studio.unit.width" value="px"/>
            </reportElement>
            <box>
                <topPen lineColor="#A0D042"/>
            </box>
            <textElement textAlignment="Left">
                <font size="35" isBold="true"/>
            </textElement>
            <textFieldExpression><![CDATA["Inhaltsverzeichnis"]]></textFieldExpression>
        </textField>
    </band>
</columnHeader>
<detail>
    <band height="20" 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 isStretchWithOverflow="true" evaluationTime="Report">
            <reportElement isPrintRepeatedValues="false" mode="Opaque" x="10" y="0" width="389" height="20" uuid="b19a02f7-3d3f-4086-86ed-5dc6859e5fd1"/>
            <textElement textAlignment="Left"/>
            <textFieldExpression><![CDATA[$F{label}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement x="399" y="0" width="70" height="20" uuid="bc43bd36-7466-457c-95e6-384410c05cbe"/>
            <textElement textAlignment="Right"/>
            <textFieldExpression><![CDATA[$V{PAGE_NUMBER} + ($F{pageIndex}+2 )]]></textFieldExpression>
        </textField>
    </band>
    <band height="28" 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 isStretchWithOverflow="true" hyperlinkType="LocalAnchor">
            <reportElement mode="Opaque" x="21" y="5" width="376" 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>
            <box>
                <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
                <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
                <bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
                <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
            </box>
            <textElement textAlignment="Left" markup="styled"/>
            <textFieldExpression><![CDATA[$F{label}]]></textFieldExpression>
            <hyperlinkAnchorExpression><![CDATA[$F{label}]]></hyperlinkAnchorExpression>
        </textField>
        <textField>
            <reportElement x="398" y="4" width="71" height="21" uuid="207a4316-1f91-4886-91f9-9a86c788a83f"/>
            <textElement textAlignment="Right"/>
            <textFieldExpression><![CDATA[($V{PAGE_NUMBER} + $F{pageIndex} + 2)]]></textFieldExpression>
        </textField>
    </band>
</detail>
<pageFooter>
    <band height="15" splitType="Stretch">
        <textField evaluationTime="Master">
            <reportElement style="Fußzeile " isPrintRepeatedValues="false" x="389" y="2" width="80" height="12" uuid="f9665296-c4e6-4f16-9b33-50619eac6150">
                <property name="com.jaspersoft.studio.unit.x" value="cm"/>
            </reportElement>
            <textElement textAlignment="Right">
                <font size="7"/>
            </textElement>
            <textFieldExpression><![CDATA[$V{MASTER_CURRENT_PAGE} != null ? $V{MASTER_CURRENT_PAGE} : $V{PAGE_NUMBER}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement style="Fußzeile " x="0" y="1" width="140" height="14" uuid="df8b430d-9e08-4c4d-9735-58c22a2332aa"/>
            <textFieldExpression><![CDATA["© Inst "+$P{Year}]]></textFieldExpression>
        </textField>
        <textField isStretchWithOverflow="true">
            <reportElement style="Fußzeile " x="184" y="1" width="100" height="12" uuid="1dccae39-e129-4892-81cb-0a36e493b0ca"/>
            <textElement textAlignment="Left"/>
            <textFieldExpression><![CDATA[" Stand: " + $P{Stand}]]></textFieldExpression>
        </textField>
    </band>
</pageFooter>

First Level锚点部分片段:

<textField isStretchWithOverflow="true" bookmarkLevel="1">
            <reportElement style="Überschrift 1" x="10" y="0" width="448" height="20" uuid="9c245808-6844-4ba6-a5b2-23e476834efb"/>
            <textElement textAlignment="Left"/>
            <textFieldExpression><![CDATA[$F{Ueberschrift}]]></textFieldExpression>
            <anchorNameExpression><![CDATA[$F{Ueberschrift}]]></anchorNameExpression>
        </textField>

第二级示例:

<textField isStretchWithOverflow="true" bookmarkLevel="2">
                <reportElement style="Überschrift 2" x="0" y="0" width="469" height="20" uuid="d6fbfb76-a764-4752-a996-95c1589a1ad5">
                    <property name="com.jaspersoft.studio.unit.width" value="cm"/>
                </reportElement>
                <box leftPadding="2"/>
                <textElement textAlignment="Left"/>
                <textFieldExpression><![CDATA[$F{Ueberschrift}]]></textFieldExpression>
                <anchorNameExpression><![CDATA[$F{Ueberschrift}]]></anchorNameExpression>
                <hyperlinkAnchorExpression><![CDATA[$F{Qiid}]]></hyperlinkAnchorExpression>
            </textField>

1 个答案:

答案 0 :(得分:0)

问题是,在TOC中显示的文本对于Jasper来说太长了(超过40个字符)。对于您的TOC标签,将书签级别设置为零,并将超链接锚表达式设置为

 $F{title}.length()>40?$F{title}.substring(0,39):$F{title}

文字字段如下:

        <textField isStretchWithOverflow="true" isBlankWhenNull="true" hyperlinkType="LocalAnchor">
                <reportElement key="" style="Standard 10pt." x="0" y="0" width="410" height="20" isRemoveLineWhenBlank="true" uuid="b19a02f7-3d3f-4086-86ed-5dc6859e5fd1"/>
                <textElement textAlignment="Left"/>
                <textFieldExpression><![CDATA[$F{label}]]></textFieldExpression>
                <hyperlinkAnchorExpression><![CDATA[$F{label}.length()>40?$F{label}.substring(0,39):$F{label}]]></hyperlinkAnchorExpression>
            </textField>

并且您需要创建一个没有任何文本的文本字段,并在文本字段旁边使用您的真实文本并将锚名称表达式设置为

$F{title}.length()>40?$F{title}.substring(0,39):$F{title}

现在适用于Docx导出

相关问题