Database-Driven Multilingual Crystal Reports

I wrote some code that parses Crystal Reports text objects and translates them to another language. It reads from a Hashtable which may be populated from a database, a text file or an XML document. The code doesn't care about the names of the text objects, just their contents.

You may have to use the String.Trim() method if the text objects contain extra spaces. Hashtable.ContainsKey(object) doesn't seem to be case-sensitive but you may not want to assume that.

C#:
  1. using CrystalDecisions.CrystalReports.Engine;
  2.  
  3. Hashtable htTranslation = new Hashtable();
  4.  
  5. // populate hashtable with (key, value) pairs
  6. // where key corresponds to the base language strings
  7. // in the Crystal Reports text objects
  8. // and value contains the translated strings
  9. ...
  10. // MyReport.rpt contains text objects with strings
  11. // in the base language
  12. MyReport cr = new MyReport();
  13. for (int i = 0; i <cr.ReportDefinition.ReportObjects.Count; i++)
  14. {
  15.     if (cr.ReportDefinition.ReportObjects[i].GetType().ToString().IndexOf("TextObject")> 0)
  16.     {
  17.         TextObject crTextObject = (TextObject)cr.ReportDefinition.ReportObjects[i];
  18.         if (htTranslation.ContainsKey(crTextObject.Text))
  19.         {
  20.             crTextObject.Text = htTranslation[crTextObject.Text].ToString();
  21.         }
  22.     }
  23. }
  24. this.CrystalReportViewer1.ReportSource = cr;

29 May 2007 | .NET, Software engineering, Crystal Reports, C# | Comments

One Response to “Database-Driven Multilingual Crystal Reports”

  1. 1 Naresh Goradara 4 May 2009 @ 1:15 pm

    Good Idea.

    Assigning one by one value to control is no fessible solution for large report.

    But is there any other way through which we can apply globalization concept of ASP.Net to crystal report.

Comments:

  1.  
  2.  
  3.