【问题标题】:Why does html tags (s, strong) not work in jasper reports?为什么 html 标签 (s, strong) 在 jasper 报告中不起作用?
【发布时间】:2019-01-22 14:15:32
【问题描述】:

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

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

有什么办法吗?

【问题讨论】:

    标签: html jasper-reports


    【解决方案1】:

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

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

    如果你喜欢使用 html,你的选择是用 <font style="text-decoration: line-through"><b> 替换它们

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

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

    示例

    jrxml

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

    结果

    【讨论】:

    • Tnx 寻求帮助,但是否可以替换 TEXT 我需要获取 TEXT isStrikeThrough
    • @Pointer 抱歉,我错过了您也需要删除线,我已经更新了答案并补充说,主体是相同的。
    猜你喜欢
    • 2014-06-21
    • 2022-06-15
    • 1970-01-01
    • 1970-01-01
    • 2018-05-05
    • 2021-04-07
    • 2021-11-17
    • 2014-05-11
    • 2016-08-06
    相关资源
    最近更新 更多