2016-07-28 82 views
2

我有一个JasperReports我们输出到html的报告。将报告导出为HTML时,如何为报告的元素提供id?

我想如何设置ID为报告的元素,以便新创建的HTML元素将具有该ID,因为后来我想使用JavaScript对元素进行一些更改。

电流JRXML代码

<pageHeader> 
     <band height="40" splitType="Stretch"> 
      <staticText> 
       <reportElement key="staticText-1" mode="Opaque" x="0" y="20" width="730" height="20" forecolor="#FFFFFF" backcolor="#5F8A1B"/> 
       <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="Center" verticalAlignment="Middle" rotation="None" lineSpacing="Single"> 
        <font fontName="Verdana" size="12" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica" pdfEncoding="Cp1252" isPdfEmbedded="false"/> 
       </textElement> 
       <text><![CDATA[Test ]]></text> 
      </staticText> 
     </band> 
    </pageHeader> 

以上JRXML代码被转换为HTML TD。只是想知道我们可以给这个代码的id或名称?

回答

2

您应该使用属性net.sf.jasperreports.export.html.id来指示html导出的id。

添加到报表元素(例如设置ID为HTML元素myId

<property name="net.sf.jasperreports.export.html.id" value="myId"/> 

在您的例子

<pageHeader> 
    <band height="40" splitType="Stretch"> 
     <staticText> 
      <reportElement key="staticText-1" mode="Opaque" x="0" y="20" width="730" height="20" forecolor="#FFFFFF" backcolor="#5F8A1B"> 
       <property name="net.sf.jasperreports.export.html.id" value="myId"/> 
      </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="Center" verticalAlignment="Middle" rotation="None" lineSpacing="Single"> 
       <font fontName="Verdana" size="12" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica" pdfEncoding="Cp1252" isPdfEmbedded="false"/> 
      </textElement> 
      <text><![CDATA[Test ]]></text> 
     </staticText> 
    </band> 
</pageHeader>