2

iReportでの日付のフォーマットに問題があります

私のPCはロケール言語をフランス語に設定しましたが、iReportがレポートを生成すると、英語のロケールでフォーマットされた日付が見つかります。

これが私のjrxmlファイルからのいくつかのコードです:

<band height="41" splitType="Stretch">
    <textField pattern="dd/MM/yyyy h.mm a">
        <reportElement uuid="fb711e77-c949-4a99-9b52-109aae00c8ed" x="87" y="19" width="100" height="20"/>
        <textElement/>
        <textFieldExpression><![CDATA[$P{datenow}]]></textFieldExpression>
    </textField>
    <staticText>
        <reportElement uuid="51fb76a0-829e-4c36-b474-3ff9c7d4c239" x="41" y="19" width="48" height="20"/>
        <textElement>
            <font isBold="true" isItalic="true"/>
        </textElement>
        <text><![CDATA[Fes Le : ]]></text>
    </staticText>
</band>

これが私にとってどのように表示されるかです:Fri Sep 28 09:59:00

私のターゲットフォーマットはvendredi 28 septembre 2012 09:59:(フランス語

何か考えはありますか?

4

1 に答える 1

3

あなたの質問は、iReportで日付形式(月の名前)を変更する方法と重複していますか?IReportでREPORT_LOCALEを設定しますか?投稿。


  • iReportでロケールを設定するには、ダイアログオプション-コンパイルと実行iReport- >ツール->オプションメニューから)を呼び出す必要があります。

言語設定ダイアログ

このtextFieldの場合:

<textField pattern="EEEEE dd MMMMM yyyy">
    <reportElement x="0" y="0" width="100" height="20"/>
    <textElement/>
    <textFieldExpression><![CDATA[$F{date}]]></textFieldExpression>
</textField>

結果は次のようになります。

iReportでのプレビューによる結果

注: iReportでのプレビューでのみ機能します。

Map<String, Object> params = new HashMap<String, Object>(); 
params.put(JRParameter.REPORT_LOCALE, Locale.FRENCH); 
JasperFillManager.fillReportToFile(compiledReportName, params); 

このようなコードで生成されたレポートの結果は同じになります。


作業サンプル、jrxmlファイル:

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport ...  whenNoDataType="AllSectionsNoDetail" ...>
    <parameter name="date" class="java.util.Date" isForPrompting="false">
        <defaultValueExpression><![CDATA[new Date()]]></defaultValueExpression>
    </parameter>
    <title>
        <band height="50">
            <textField pattern="EEEEE dd MMMMM yyyy">
                <reportElement x="200" y="11" width="228" height="20"/>
                <textElement/>
                <textFieldExpression><![CDATA[$P{date}]]></textFieldExpression>
            </textField>
        </band>
    </title>
</jasperReport>

Javaコード:

Map<String, Object> params = new HashMap<String, Object>();
params.put("date", new Date());
params.put(JRParameter.REPORT_LOCALE, Locale.FRENCH);

JasperReport jasperReport = JasperCompileManager.compileReport(reportSource);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, connection);

JasperExportManager.exportReportToPdfFile(jasperPrint, outputFile);

結果は次のようになります。

AdobeReaderで生成されたレポート

于 2012-09-28T10:16:57.750 に答える