Jasper 报告中的一些货币符号没有出现
Some currency Symbol in Jasper report is not coming
我已经使用 jaspersoft studio 创建了一个 jasper 报告模板,我正在使用 java 代码填充该模板。我在报告中有一些数据需要本地化,为此我在 java.
中通过以下代码看到了 "locale"
Locale locale = new Locale("zh", "CN");
templateParameters.put("REPORT_LOCALE", locale); //A map to pass to report
我也试过了 -
Locale locale = java.util.Locale.CHINA;
填充报告中有 "Number formatting" 但缺少货币符号(只有美元、英镑、欧元符号出现)
下面是我在 jasper 报告中用来填充文本字段的代码 -
NumberFormat.getCurrencyInstance($P{REPORT_LOCALE}).format($P{Param_Name})
如果有人能指出错误或提供一些建议,我将不胜感激。
我认为您的问题与字体支持有关。
如果使用JRPdfExporter.
,我们应该使用Font Extensions
我尝试使用支持 中文 的字体,在这种情况下一切正常。我不知道为什么使用大量其他字体不行帮助
例子
Java代码
Map<String, Object> params = new HashMap<>();
params.put(JRParameter.REPORT_LOCALE, Locale.CHINA);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, new JREmptyDataSource());
报告模板
jrxml文件中有4个textField:两个使用支持中文的字体另一个 2 - 没有它。
<?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="Show currency" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<parameter name="value" class="java.lang.Double" isForPrompting="false">
<defaultValueExpression><![CDATA[1234.567]]></defaultValueExpression>
</parameter>
<title>
<band height="70">
<textField>
<reportElement x="10" y="10" width="300" height="15"/>
<textElement>
<font fontName="Sharp Dawn"/>
</textElement>
<textFieldExpression><![CDATA[NumberFormat.getCurrencyInstance(new Locale("zh", "CN")).format($P{value})]]></textFieldExpression>
</textField>
<textField>
<reportElement x="10" y="25" width="300" height="15"/>
<textElement>
<font fontName="Sharp Dawn"/>
</textElement>
<textFieldExpression><![CDATA[NumberFormat.getCurrencyInstance($P{REPORT_LOCALE}).format($P{value})]]></textFieldExpression>
</textField>
<textField>
<reportElement x="3" y="40" width="300" height="15"/>
<textFieldExpression><![CDATA[NumberFormat.getCurrencyInstance($P{REPORT_LOCALE}).format($P{value})]]></textFieldExpression>
</textField>
<textField>
<reportElement x="3" y="55" width="300" height="15"/>
<textFieldExpression><![CDATA[NumberFormat.getCurrencyInstance(new Locale("zh", "CN")).format($P{value})]]></textFieldExpression>
</textField>
</band>
</title>
</jasperReport>
输出结果
借助 JRPdfExporter 生成的 pdf 文件看起来像
元符号仅对第一组显示。
我已经使用 jaspersoft studio 创建了一个 jasper 报告模板,我正在使用 java 代码填充该模板。我在报告中有一些数据需要本地化,为此我在 java.
中通过以下代码看到了 "locale"Locale locale = new Locale("zh", "CN");
templateParameters.put("REPORT_LOCALE", locale); //A map to pass to report
我也试过了 -
Locale locale = java.util.Locale.CHINA;
填充报告中有 "Number formatting" 但缺少货币符号(只有美元、英镑、欧元符号出现) 下面是我在 jasper 报告中用来填充文本字段的代码 -
NumberFormat.getCurrencyInstance($P{REPORT_LOCALE}).format($P{Param_Name})
如果有人能指出错误或提供一些建议,我将不胜感激。
我认为您的问题与字体支持有关。
如果使用JRPdfExporter.
,我们应该使用Font Extensions我尝试使用支持 中文 的字体,在这种情况下一切正常。我不知道为什么使用大量其他字体不行帮助
例子
Java代码
Map<String, Object> params = new HashMap<>();
params.put(JRParameter.REPORT_LOCALE, Locale.CHINA);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, new JREmptyDataSource());
报告模板
jrxml文件中有4个textField:两个使用支持中文的字体另一个 2 - 没有它。
<?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="Show currency" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<parameter name="value" class="java.lang.Double" isForPrompting="false">
<defaultValueExpression><![CDATA[1234.567]]></defaultValueExpression>
</parameter>
<title>
<band height="70">
<textField>
<reportElement x="10" y="10" width="300" height="15"/>
<textElement>
<font fontName="Sharp Dawn"/>
</textElement>
<textFieldExpression><![CDATA[NumberFormat.getCurrencyInstance(new Locale("zh", "CN")).format($P{value})]]></textFieldExpression>
</textField>
<textField>
<reportElement x="10" y="25" width="300" height="15"/>
<textElement>
<font fontName="Sharp Dawn"/>
</textElement>
<textFieldExpression><![CDATA[NumberFormat.getCurrencyInstance($P{REPORT_LOCALE}).format($P{value})]]></textFieldExpression>
</textField>
<textField>
<reportElement x="3" y="40" width="300" height="15"/>
<textFieldExpression><![CDATA[NumberFormat.getCurrencyInstance($P{REPORT_LOCALE}).format($P{value})]]></textFieldExpression>
</textField>
<textField>
<reportElement x="3" y="55" width="300" height="15"/>
<textFieldExpression><![CDATA[NumberFormat.getCurrencyInstance(new Locale("zh", "CN")).format($P{value})]]></textFieldExpression>
</textField>
</band>
</title>
</jasperReport>
输出结果
借助 JRPdfExporter 生成的 pdf 文件看起来像
元符号仅对第一组显示。