When exporting report to HTML, how to give id to r

2019-02-26 02:43发布

I have a JasperReports report which we export to html.

I want to how to set id to report's element so that newly created html element will have that id, since later I want to make some changes to the element using JavaScript.

Current jrxml code

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

Above jrxml code is converted to html td. Just want to know can we give id or name to this code?

1条回答
▲ chillily
2楼-- · 2019-02-26 03:18

You should use the property net.sf.jasperreports.export.html.id to indicate id for html export.

Add to the report element (example sets id to html element as myId)

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

In your example

<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>
查看更多
登录 后发表回答