Sign In  Sign Up Live-Chat

Setting data format not working

Last post 07-02-2008, 9:36 AM by Laurence. 2 replies.
Sort Posts: Previous Next
  •  07-02-2008, 8:24 AM 133977

    Setting data format not working

    Hi,

    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!

     
  •  07-02-2008, 9:28 AM 134026 in reply to 133977

    Re: Setting data format not working

    Hi,

    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);
       wb.Save("d:\\test\\style_column.xls");

     

    Thank you.


    Amjad Sahi
    Support Developer,
    Aspose Nanjing Team
    Contact Us
     
  •  07-02-2008, 9:36 AM 134030 in reply to 133977

    Re: Setting data format not working

    Please try following code:

    StyleFlag numberFormatFlag = new StyleFlag();

    numberFormatFlag.NumberFormat = true;

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

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


    Laurence Chen
    Chief Architect
    Aspose Nanjing Team
    About Us
    Contact Us
     
View as RSS news feed in XML