Jump to content

Recommended Posts

Posted

Hi all! I am developing an application that combine 2 languages, spanish and english. The user can select english for texts and spanish to show dates and numbers in spanish format. So in my reports i have to implement that functionality. I send me one parameter called "LOCALE_NUMBER_DATES" that its a simple String like "ES" or "EN" My first solution was to apply a format in the "Text Field Expression" like this:

$P{LOCALE_NUMBER_DATES}.equalsIgnoreCase( "EN" )? new java.text.DecimalFormat("###,##0.00", new java.text.DecimalFormatSymbols(java.util.Locale.ENGLISH)).format($F{certificationSummary}.getProductiveHoursTotal())+ " " + $P{CURRENCY} : new java.text.DecimalFormat("###,##0.00", new java.text.DecimalFormatSymbols(java.util.Locale.ITALIAN)).format($F{certificationSummary}.getProductiveHoursTotal())+ " " + $P{CURRENCY} :""

 

Its work! but Excel cells dont recognize number formats so i had to change the solution. To make sure that Excel recognizes Number (or dates) formats i had to delete my textfield expression and delegate to a "Pattern" on textfield and i thought that "Pattern expression" helps me but i do not get my purpose.

In "Pattern expression" i use a variable called "LocaleNumbers" that expression is: $P{LOCALE_NUMBER_DATES}.equalsIgnoreCase("ES")? new DecimalFormat("###,##0.00", new java.text.DecimalFormatSymbols(java.util.Locale.ITALIAN)).toPattern():new DecimalFormat("###,##0.00", new java.text.DecimalFormatSymbols(java.util.Locale.ENGLISH)).toPattern()

but its not work! I think because that expression returns always the same String and then Jasper get the "REPORT_LOCALE" global parameter and apply .format() function. Am i right? If yes... Does anyone know any other way to achieve this?

 

Can someone write an example of use of "Pattern Expression" ?? I not see nothing in Jasper Sample Project. 

 

Thanks in advance

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

  • 6 months later...
Posted

I had the same problem you did, thought I'd post my solution even if it's too late to help you.

In the Pattern Expression you should not be returning a pattern, but rather a string from which a pattern will be made.

For example, in my report I wanted numbers formatted as "#,##0.00;(#,##0.00)" but when the field label was "Net Invoiced" i wanted the output to be bold.  So, in Pattern Exp. I put:

$F{label}.matches("Net Invoiced")? "<b>#,##0.00;(#,##0.00)</b>":"#,##0.00;(#,##0.00)"

Hope that helps someone!

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...