2017-07-25 86 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