Formatting NOT showing until I double click on cell

Hi,

Great product!

I’m using the following code to apply currency formatting on a column

Style styleCurrency;
styleCurrency = wb.Styles[wb.Styles.Add()];
styleCurrency.Number = 5; //Sets the currency format.
StyleFlag flagCurrency;
flagCurrency = new StyleFlag();
flagCurrency.NumberFormat = true;
sheet.Cells.Columns[4].ApplyStyle(styleCurrency, flagCurrency);

the formatting isn’t showing up when I open the excel file until I double click on each individual cell.

What am I doing wrong?

I also tried

sheet.Cells.Columns[4].Style.Custom = “$#,##0”;

but had the same issue.

When I look at the cell or the column’s formatting it has the right one selected (currency) but it just doesn’t show.

Thanks!

Hi,

I think the column (E) cell values must be string values instead of numbers. Please use Cell.PutValue(string stringValue, true) method to convert string value to numeric value in a cell.

I write a sample code for your reference here which works abs fine:

Sample code:

//Instantiate the Workbook object
Workbook wb = new Workbook();
Worksheet sheet = wb.Worksheets[0];
//Set the name of worksheet
sheet.Name = "Data";
Cells cells = wb.Worksheets[0].Cells;
//Put some values in the fifth column cells.
cells["E1"].PutValue("Sale1");
cells["E2"].PutValue(70000);
//NOTE: Dont try to use the code i.e., cells["E2"].PutValue("70000"); as it will give you string value (Number stored as text ...green triangle attached).
//Alternatively you may also use cells["E2"].PutValue("70000", true);
cells["E3"].PutValue(55000);
cells["E4"].PutValue(30000);
cells["E5"].PutValue(85000);
cells["E6"].PutValue(90000);
Style styleCurrency;
styleCurrency = wb.Styles[wb.Styles.Add()];
styleCurrency.Number = 5; //Sets the currency format.
StyleFlag flagCurrency;
flagCurrency = new StyleFlag();
flagCurrency.NumberFormat = true;
sheet.Cells.Columns[4].ApplyStyle(styleCurrency, flagCurrency);

wb.Save("f:\\test\\currecyformatbook1.xls");

If you still find any problem, please post your generated file here.

Thank you.