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

Free Support Forum - aspose.com

Setting data format not working


I tried to set data format string (such as #,##0.00) using Style.Custom property but didn't work.

Here is my code:

NumericColumnStyle.Custom = "#,##0";

cells.Columns[iPos].ApplyStyle(NumericColumnStyle, fontStyleFlag);

Did I do it correctly? Any suggestions?



Thanks for considering Aspose.

Well, in the new Aspose.Cells versions, we put some work and optimized its performance. So, if you need to apply some style formattings a whole column / row, you should use Cells.ApplyColumnStyle / ApplyRowStyle() methods which we introduced recently.

Consult the following code for you need:

Workbook wb = new Workbook();
Worksheet sheet = wb.Worksheets[0];
Style style;
StyleFlag flag;
style = sheet.Cells.Columns[0].Style;
//Or add a new style like the following.
//style = wb.Styles[wb.Styles.Add()];
style.Custom = "#,##0";
flag = new StyleFlag();
flag.NumberFormat = true;
sheet.Cells.ApplyColumnStyle(0,style, flag);

Thank you.

Please try following code:

StyleFlag numberFormatFlag = new StyleFlag();

numberFormatFlag.NumberFormat = true;

NumericColumnStyle.Custom = "#,##0";

cells.Columns[iPos].ApplyStyle(NumericColumnStyle, numberFormatFlag);