2017-07-25 74 views
0

我正在生成一個帶目錄的碧玉書,需要將它導出爲DOCx。問題是當我點擊TOC中的第一級書籤時,沒有任何反應。當我單擊TOC中的任何第二級標籤時,Jasper跳轉到封面(PDF導出中的單擊第二級標籤跳轉到報告中的右側錨點)。我有錨水平1和2和鏈接目標是自我與類型無。 TOC JRXMLJasper Book Docx導出的內容導航

<?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> 

第一級錨定部分片段:

<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

你認爲你可以將[mcve]放在一起嗎?我們可以更容易地測試並試圖理解爲什麼。 –

回答

0

的問題是,要在顯示的文本TOC對Jasper來說太長了(longe超過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> 

,你需要在沒有任何文字和0級創建一個文本字段與你的真實文字,並設置錨點名稱表達你的文本字段

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

現在,它適用於DOCX出口

旁210