JasperReports: Not support & sign when i use style

两盒软妹~` 提交于 2019-12-10 18:32:37

问题


Working in JasperReports:

<style pdfFontName="Helvetica-BoldOblique" isBold="true" isItalic="true" 
forecolor="red">Instruction and instruction</style>

Not Working in JasperReports:

<style pdfFontName="Helvetica-BoldOblique" isBold="true" isItalic="true"
forecolor="red">Instruction & instruction</style>

Why this is happening?


回答1:


I have used &amp;amp; instead of "&" and it is working in jasper report.

<style pdfFontName="Helvetica-BoldOblique" isBold="true" isItalic="true"
forecolor="red">Instruction &amp;amp; instruction</style>

//In text filed i have used style tag.

<textField isStretchWithOverflow="true" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self" >
                <reportElement
                    x="0"
                    y="0"
                    width="290"
                    height="15"
                    key="textField"
                    isRemoveLineWhenBlank="true"/>
                <box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" rightPadding="5" bottomBorder="None" bottomBorderColor="#000000"/>
                <textElement textAlignment="Center" isStyledText="true">
                    <font size="9"/>
                </textElement>
            <textFieldExpression   class="java.lang.String"><![CDATA[<style pdfFontName="Helvetica-BoldOblique" isBold="true" isItalic="true"
forecolor="red">Instruction &amp;amp; instruction</style>]]></textFieldExpression>
            </textField>



回答2:


Try to use &amp; instead of using & symbol.

The working sample:

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport ... whenNoDataType="AllSectionsNoDetail">
    <style name="style1" forecolor="#FF0000" fontName="Serif" isBold="true" isItalic="true"/>
    <title>
        <band height="182" splitType="Stretch">
            <staticText>
                <reportElement style="style1" x="27" y="15" width="515" height="20"/>
                <textElement/>
                <text><![CDATA[Instruction and instruction]]></text>
            </staticText>
            <staticText>
                <reportElement style="style1" x="27" y="46" width="515" height="20"/>
                <textElement/>
                <text><![CDATA[Instruction & instruction]]></text>
            </staticText>
            <staticText>
                <reportElement x="27" y="78" width="515" height="20"/>
                <textElement markup="styled"/>
                <text><![CDATA[<style isBold='true'>Instruction and instruction</style>]]></text>
            </staticText>
            <staticText>
                <reportElement x="27" y="108" width="515" height="20"/>
                <textElement markup="styled"/>
                <text><![CDATA[<style isBold='true'>Instruction &amp; instruction</style>]]></text>
            </staticText>
        </band>
    </title>
</jasperReport>

Note: The styled markup is using in this sample.

The result will be:


For more details you can view Creating Styled Text Using a Markup Language post and my answer on Style a text field in JasperReports question.



来源:https://stackoverflow.com/questions/13024334/jasperreports-not-support-sign-when-i-use-style

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!