【问题标题】:Some currency Symbol in Jasper report is not comingJasper 报告中的某些货币符号未出现
【发布时间】:2016-11-03 13:11:25
【问题描述】:

我使用 jaspersoft studio 创建了一个 jasper 报告模板,并且正在使用 java 代码填充该模板。我在报告中有一些需要本地化的数据,为此我在 java 中通过下面的代码看到了“语言环境”。

Locale locale = new Locale("zh", "CN");
templateParameters.put("REPORT_LOCALE", locale); //A map to pass to report

我也试过了——

Locale locale = java.util.Locale.CHINA;

在填充的报告中“数字格式”存在,但缺少货币符号(只有美元、英镑、欧元符号出现) 下面是我在 jasper 报告中用来填充文本字段的代码 -

NumberFormat.getCurrencyInstance($P{REPORT_LOCALE}).format($P{Param_Name})

如果有人能指出错误或提供一些建议,我将非常感激。

【问题讨论】:

  • 你检查过NumberFormat.getCurrencyInstance(new Locale("zh", "CN")).format($P{Param_Name})这样的表达式吗?
  • @AlexK,我在您的评论后尝试过,但没有运气。有趣的一点是符号出现在图表对象中(因为 jfree 图表),但不在 jasper 原生对象中,如文本字段、网格等。

标签: java jasper-reports


【解决方案1】:

我认为您的问题与字体支持有关。

如果使用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:两个使用支持 Chinese 的字体,另外两个 - 不支持。

<?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文件看起来像

元符号只显示第一组。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-23
    • 2012-03-27
    • 2014-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多