We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Currency Format based on Culture

Hi,

We are using Aspose.cells. We need to format the currency based on the following requirements:

we support 3 languages in our application (English, German, Dutch). The user can select the language he wants. We need to display the currency symbol that is set in our application and not the currency symbol of the currently set culture. How do I format the currency number(decimal seperator, thousands seperator) based on the selected culture? We need to display the data in excel.

Hi Gautam,


Thank you for considering Aspose APIs.

You may consider using the WorkbookSettings.NumberDecimalSeparator & NumberGroupSeparator properties for your requirement. Please check an article on this subject, and let us know if it suffices the need.

Hi,


I am not getting the option for the decimal and thousand seperator for the workbook settings. Which version have they been introduced in?

Hi again,


Adding more to my previous response, if you wish that the Excel application automatically formats the currency values based on the locale of the machine then we suggest you to use any of the built-in number formats ranging from 6 to 8 from this article. Please note, you need to set the Style.Number property and format the relevant cells/ranges accordingly. If you use this approach, the currency symbol will also automatically change according to the region/locale of the machine.

Hi,

We do not need to depend on the machine and excel settings. We have to format the number based on the language and currency selected in our application.

Thanks,
Gautam
Hi,

gautamvbaindur:
Hi,

I am not getting the option for the decimal and thousand seperator for the workbook settings. Which version have they been introduced in?

Please note, the aforementioned properties were introduced with the release of Aspose.Cells for .NET 8.3.2.

Hi,


I am now getting the options for the seperators. But how do I format the currency cell based on the language selected in the application. For example, if English is selected the currency should be displayed as $1,500.88. If Dutch is selected, the currency should be displayed as $1.500,88.

Thanks,
Gautam

Hi Gautam,


Please consider the following snippet that make use of the WorkbookSettings.CultureInfo property to format currency values according to the locale of the machine. If you check the console output of the code, you will notice that currency values are formatted correctly, however, as the cells in the sample spreadsheets are using the built-in styles therefore if you save the result on disc and load the resultant spreadsheet in Excel, the formats will be automatically changed as per region of the machine. You need to change the region of your system accordingly to see the applied changes in Excel application.

C#

string[] files = new string[] { “english.xlsx”, “dutch.xlsx” };
foreach (string file in files)
{
var book = new Workbook(dataDir + file);
var fileName = Path.GetFileNameWithoutExtension(book.FileName);
switch(fileName)
{
case “english”:
book.Settings.CultureInfo = new CultureInfo(“en-US”);
Console.WriteLine("English " + book.Worksheets[0].Cells[“A1”].StringValue);
break;
case “dutch”:
book.Settings.CultureInfo = new CultureInfo(“nl-NL”);
Console.WriteLine("Dutch " + book.Worksheets[0].Cells[“A1”].StringValue);
break;
}
}