Quantcast
Channel: SCN : All Content - All Communities
Viewing all articles
Browse latest Browse all 2136

Dynamically Change Number Format in Visual Studio

$
0
0

I did some searching on this site and google, and can't find a good solution to change number formatting in my Crystal Report.

This was the closest thing that I could find: ( Setting numeric format for a report field dynamically using C# ), but this seems to be to modify the report template itself, not the loaded report document.

I'd like my .rpt file to remain in tact. The report is financial and was initially designed for USD currency.

To handle other currencies, my solution is to add the Currency Code to the report. I also need to remove the currency symbol. I could do this in the designer. But the part that requires me to do this in code, is the need to dynamically change the thousand separator on-the-fly.

Swiss Franks show the thousand separator as 1'000.00

 

I'd really like to do something like this:

 

/* BEGIN CODE */

CrystalDecisions.CrystalReports.Engine.ReportDocument report;

report = new CrystalDecisions.CrystalReports.Engine.ReportDocument();

report.Load(rptFileName);

 

if (currencyCode =="CHF")

{

     foreach (CrystalDecisions.CrystalReports.Engine.ReportObject obj in report.ReportDefinition.ReportObjects){

          CrystalDecisions.CrystalReports.Engine.FieldObject fld = (CrystalDecisions.CrystalReports.Engine.FieldObject)obj;

          fld.FieldFormat.NumericFormat.ThousandSymbol ="'";

          //Unfortunately, ThousandSymbol doesn't exist in CrystalDecisions.CrystalReports.Engine.NumericFieldFormat.

          //Only in CrystalDecisions.ReportAppServer.ReportDefModel.NumericFieldFormat as specified in the thread link above;

          //...which I tried, but it doesn't seem to modify my ReportDocument to print the ThousandSymbol with the "'".

     }

}

 

report.SetDataSource(data);

report.ExportToDisk(ExportFormatType.PortableDocFormat, pdfFileName);

 

/* END CODE */

 

Is there a way to change the FieldFormat for the ReportDocument loaded in memory? Without changing the .rpt file on disk?

I really don't want to have to maintain a separate .rpt file for every financial report that we have in our application.

 

I'm using Visual Studio Premium 2013 (12..21005.1)
My application is compiled with .NET 4.0

Crystal for VS (13.0.16.1954)


Viewing all articles
Browse latest Browse all 2136

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>