【发布时间】:2019-01-22 14:15:32
【问题描述】:
【问题讨论】:
标签: html jasper-reports
【问题讨论】:
标签: html jasper-reports
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><s></s> and <strong><strong></strong> will not work but <font style=\"text-decoration: line-through\"><font style=\"text-decoration: line-through\"></font> and <b><b></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><s></s> and <strong><strong></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>
结果
【讨论】: