2
votes

I'm working with a Crystal Reports export with different localization. For this example, I'm trying to set the localization to French which uses Euros.

I set the localization with the following C# code:

    ReportDocument report = new ReportDocument();

    report.ReportClientDocument.LocaleID = CrystalDecisions.ReportAppServer.DataDefModel.CeLocale.ceLocaleFrench;
    report.ReportClientDocument.PreferredViewingLocaleID = CrystalDecisions.ReportAppServer.DataDefModel.CeLocale.ceLocaleFrench;
    report.ReportClientDocument.ProductLocaleID = CrystalDecisions.ReportAppServer.DataDefModel.CeLocale.ceLocaleFrench;

When I export the report the following value is displayed:

135,00 $

Notice that the format of the number changed correctly, but the currency symbol didn't.

I've been searching for a solution but pretty much everything focuses on changing the currency at design time, but I need to be able to change it at run time depending on some other values that the user selects.

I've seen some hints around using parameters to pass in a value and using a formula in the designer but I'm not familiar enough with Crystal Reports to figure it out.

I'm using Crystal Reports 10.5 with Visual Studio 2010 and .Net 3.5.

Any help or tips is appreciated.

1

1 Answers

3
votes

I figured it out and based on the research that I've done I think that this is the only way to do it.

I'm pretty sure that the symbol doesn't change on purpose. Following the logic that a report is used for only one type of currency, even though the format will change with culture, the actual currency value is the same. $100 is always a $100 no matter what language the report is viewed in and this way, the report doesn't have to worry about converting the data to different amount.

In my application, the data is stored as just a number and the currency is determined by other values in the database and the code.

But to get to the point, I specified the locale of the report based on the code in my question. Then to change the currency, symbol I had to go into the report designer and format the currency questions.

In the 'Number' tab of the Format Editor, make sure the 'Display Currency Symbol' box is checked. Then click on the 'Customize' button and the 'Currency Symbol' tab. Go to the Formula Workshop for the currency symbol and then put in the following code:

Local StringVar locale := LowerCase(ContentLocale);
if locale = "fr_fr" then
    "€"
else if (locale = "en_gb") then 
    "£"
else if(locale = "en_us" OR locale = "en_ca") then
    "$"
else
    ""

This is just an example of the languages that I'm supporting but right now, but I think it gets the point across. Also note that Crystal uses underscores in the locale IDs instead of hyphens.

Kind of a log winded answer but hopefully this will help someone else.