How to display currency data with correct currency symbol in cells according to user's cultureUI settings in browser?

Hello,

I found sample code to display currency data in cells. The problem is that the data always displays in $ eventhought the culture setting in my browser is set to en-GB. Can you please let me know how to make my code to display the data with the Euro sign in front? I need to display the first column - cells.Columns[0] in currency format. Below is my code:

Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(this.Request.UserLanguages[0]);

Thread.CurrentThread.CurrentUICulture = new CultureInfo(this.Request.UserLanguages[0]);

Workbook workbook = new Workbook();

Worksheet sheet = workbook.Worksheets[0];

sheet.Name = "show currency";

string _SaveAsFileName = SaveAsFileName + ".xls";

//Obtain the cells of the first worksheet.

Cells cells = workbook.Worksheets[0].Cells;

//Adding a new Style to the styles collection of the Excel object

workbook.Styles.Add();

workbook.Styles.Add();

workbook.Styles.Add();

//Accessing the newly added Style to the Excel object

Aspose.Cells.Style styleCurrency = workbook.Styles[0];

Aspose.Cells.Style styleDates = workbook.Styles[1];

Aspose.Cells.Style styleTitles = workbook.Styles[2];

styleCurrency.Number = 15;

styleDates.Custom = System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern.ToLower();

styleTitles.HorizontalAlignment = TextAlignmentType.Center;

styleTitles.Font.Color = System.Drawing.Color.Blue;

//Accessing a column from the Columns collection

Column columnCurrency = cells.Columns[0];

Column columnDates = cells.Columns[3];

//Assigning the Style object to the Style property of the column

columnCurrency.Style = styleCurrency;

columnDates.Style = styleDates;

////Accessing a row from the Rows collection

//Row row = cells.Rows[0];

////Assigning the Style object to the Style property of the row

//row.Style = style;

//Row rowTitle = cells.Rows[0];

//rowTitle.Style = styleTitles;

sheet.Cells["A1"].PutValue(salary);

sheet.Cells["B1"].PutValue(lastname);

sheet.Cells["C1"].PutValue(firstname);

sheet.Cells["D1"].PutValue(hiredate);

sheet.Cells["E1"].PutValue(active);

sheet.Cells["F1"].PutValue(usertypeid);

sheet.Cells["G1"].PutValue(deptid);

sheet.Cells["H1"].PutValue(MI);

sheet.Cells["A1"].Style.HorizontalAlignment = TextAlignmentType.Center;

// sheet.Cells.Columns[0].Style.Custom = Functions.getDateFormatString(this.Page);

sheet.Cells.ImportDataTable(dtData, false, "A2");

sheet.AutoFitColumns();

workbook.Save(_SaveAsFileName, FileFormatType.Default, Aspose.Cells.SaveType.OpenInExcel, this.Response);

Thank you very much in advance for your help.

Hi,

I think you may set your system's regional and local settings for your need i.e., in WinXp, Click Control Panel | Regional and Language Options.

Thank you.

and you may also specify the custom formats by code:

e.g.,

style.Custom = "[$€-2] #,##0.00";

Thank you.

By browser is set to use "en-GB". The date column is displaying correctly in the en-GB date format using this line in my code:

styleDates.Custom = System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern.ToLower();

However, this line in my code needs to reflect the correct currency symbol as specified in my browser which is set to "en-GB" as well:

styleCurrency.Number = ?????????;

I prefer not to hard code the currency symbol. I would like to use what is selected in the user’s browser as their default language setting. Visitors on my site could be from different countries in Europe.

I found a workaround:

string currencySymbol = System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.CurrencySymbol.ToString();

string currencyFormat = "@#,##0.00_);(@#,##0.00)";

styleCurrency.Custom = currencyFormat.Replace("@", currencySymbol);