2012-09-28 27 views
2

我有格式化日期問題的iReportiReport的:如何基於法文場所

的我的電腦我配置的語言環境語言法國但格式化時的日期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(以法國

你hav有什麼想法嗎?

+1

你可以看一下我的答案【如何更改日期格式(月名)在iReport的?](http://stackoverflow.com/a/8654787/876298)和[在iReport的設置REPORT_LOCALE?](HTTP:// stackoverflow.com/a/8847962/876298)與此問題相關的帖子 –

回答

2

您的問題重複發佈How to change date format (month name) in iReport?Setting REPORT_LOCALE in IReport?的帖子。


  • 對於的iReport設置區域,那麼你應該調用對話框選項 - 編輯和exectution(通過iReport的 - >工具 - >選項菜單)。

Dialog for setting language

對於這個文本字段

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

結果將是:

Result via preview in iReport

注意:它只的作品對於p請參閱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); 

結果是:

The generated report in Adobe Reader

+1

我測試的兩種方式,但相同的結果,總是:**週五11年9月28日:29:37 ** – simonTifo

+0

@simonTifo你嘗試的樣本?它對你有用嗎? –

+0

現在的作品,非常感謝你的問題是:不是有:'<參數名稱=「datenow」級=「java.util.Date」 />'我有:'<參數名稱=「datenow」級=「java.lang.String」/>' – simonTifo