为什么 html 标签(s,strong)在 jasper 报告中不起作用?

Poi*_*ter 3 html jasper-reports

我添加了静态文本 html 标签,但单击预览粗体和删除线后无法正确显示。

此外,当从数据库加载数据时,它无法正确显示。

例子

有什么解决办法吗?

Pet*_*erg 5

Jasper Report 不支持所有 html 标签,支持标签在Styled Text Sample中定义

如您所见<s><strong>不支持标记。

您的选择是,以取代他们<font style="text-decoration: line-through">,并<b>如果你喜欢使用HTML

或者

<style isStrikeThrough="true">并且<style isBold="true">,然后使用样式的文本,而不是HTML。

如果您有动态数据,您可以使用 java 来替换它

${myField}.replace("<s>","<font style=\"text-decoration: line-through\">").
        replace("</s>","</font>").
        replace("<strong>","<b>").replace("</strong>","</b>")
Run Code Online (Sandbox Code Playgroud)

如果需要替换多个标签,我建议在java(静态)中创建一个方法并调用此方法而不是在报告中执行替换

例子

xml文件

<?xml version="1.0" encoding="UTF-8"?>
<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="html" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="fe5b2242-b491-46ba-8456-aa71ae5e2212">
    <queryString>
        <![CDATA[]]>
    </queryString>
    <title>
        <band height="53" splitType="Stretch">
            <textField>
                <reportElement x="0" y="0" width="210" height="50" uuid="e462bb03-e884-4b5b-b41f-2867a4bd63b2"/>
                <textElement markup="html"/>
                <textFieldExpression><![CDATA["<s>&lt;s&gt;</s> and <strong>&lt;strong&gt;</strong> will not work but <font style=\"text-decoration: line-through\">&lt;font style=\"text-decoration: line-through\"&gt;</font> and <b>&lt;b&gt;</b> will"]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="220" y="0" width="220" height="50" uuid="744bb631-d03a-452e-ae5e-19e7ef5a378a"/>
                <textElement markup="html"/>
                <textFieldExpression><![CDATA["With java however you can replace'em and both <s>&lt;s&gt;</s> and <strong>&lt;strong&gt;</strong> will work".replace("<s>","<font style=\"text-decoration: line-through\">").replace("</s>","</font>").replace("<strong>","<b>").replace("</strong>","</b>")]]></textFieldExpression>
            </textField>
        </band>
    </title>
</jasperReport>
Run Code Online (Sandbox Code Playgroud)

结果

结果