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

Free Support Forum - aspose.com

How to avoid CultureCustom setting?

Hi Apose team,

When we try to set cell style with style number, culture custom for that cell is set. How to avoid this behaviour?

Here is our code:

Workbook workbook = new Workbook(@“C:\Users\rkoncare\Downloads\Input.xlsx”);
Worksheet worksheet = workbook.Worksheets[0];
Cell cell = worksheet.Cells[“I22”];
Style style = cell.GetStyle(true);
Console.WriteLine(style.CultureCustom == null ? “null” : style.CultureCustom);
style.Number = 7;
Console.WriteLine(style.CultureCustom == null ? “null” : style.CultureCustom);

Output of this code is:
null
“$”#,##0.00_);("$"#,##0.00)

I attached Input.xlsx file.
Input.zip (11.4 KB)

Thanks in advance.

Koncarevic Radovan

@rkoncarevic

Please create an Excel file using Microsoft Excel and then set its number format to Currency (item 3 - as shown in screenshot) then run the following code and check the Style st in Quick Watch, you will see, Custom, CultureCustom and Number all are set.

It means, even if you set the number format via Microsoft Excel, it will affect all of these three properties. However, Number property takes precedence. So when Number property is set, Culture and CultureCustom does not matter at all.

Download Links:
Source Excel File.zip (5.8 KB)

C#

Workbook wb = new Workbook("source.xlsx");

Worksheet ws = wb.Worksheets[0];

Cell cell = ws.Cells["E3"];

Style st = cell.GetStyle();
st.Number = 7;
cell.SetStyle(st);

Style st1 = cell.GetStyle();

wb.Save("out.xlsx");

Screenshots:

Shakeel,

You are absolutely right, that is how Excel works even if it is nor logically to me :slight_smile: Thanks for your help.

Regards,
Radovan

@rkoncarevic

Thanks for using Aspose APIs.

It is good to know that you figured out this issue. Thank you and have a good day. :slight_smile: