Cell formatting

Posted by: pragati-sd-fp on 10 September 2017, 10:56 am EST

  • Posted 10 September 2017, 10:56 am EST


    I want to format the negative value in cell. I need to enclose the value in brackets, removing negative sign. I use the code -
    gcActiveSheet.Rows[iRCnt].Formatter = new GrapeCity.Windows.SpreadSheet.Data.GeneralFormatter(GrapeCity.Windows.SpreadSheet.Data.FormatMode.CustomMode, "0_);(0)");

    But, its formatting some cells and not all. As per my observation, the direct values are not getting formatted & only the values with formula are getting affected with the code.

    Please, help.




  • Replied 10 September 2017, 10:56 am EST

    Hi Pragati,

    I used the following code to set the formatter for a cell and value for the cell being formatted correctly.

       double dvalue = 12345.6789;

                // c C
                sheet.Cells[0, 0].Value = "c C";
                sheet.Cells[0, 1].Formatter = new GeneralFormatter(FormatMode.StandardNumericMode, "c");
                sheet.Cells[0, 1].Value = dvalue;
                sheet.Cells[0, 2].Formatter = new GeneralFormatter(FormatMode.StandardNumericMode, "C");
                sheet.Cells[0, 2].Value = dvalue;

    Please provide me a sample application to debug this further.


  • Replied 10 September 2017, 10:56 am EST


    How are you setting the direct values? My guess is that the direct values are string values. The format only applies to number values. If the formula results are number values (e.g. 1234.56) then the format would be applied to the formula results. If the direct values are string values that look like numbers (e.g. "1234.56") then the format would not be applied to the direct values.

  • Replied 10 September 2017, 10:56 am EST

    Hello Deepak,
    Thanks for your reply.
    Actually, data bounded to sheet has some string values & some formula values.
    The formatting getting applied to formula values, but not to the string values.
    Due to some permission constraint, I cannot attach sample application for you.
    Please, check -
                double dvalue = -12345.6789;
                string strValue = "-12345.6789";

                // c C
                gcSpread.Sheets[0].Cells[0, 0].Value = "c C";
                gcSpread.Sheets[0].Cells[0, 1].Formatter = new GeneralFormatter(FormatMode.StandardNumericMode, "c");
                gcSpread.Sheets[0].Cells[0, 1].Value = dvalue;
                gcSpread.Sheets[0].Cells[0, 2].Formatter = new GeneralFormatter(FormatMode.CustomMode, "0_);(0)");
                gcSpread.Sheets[0].Cells[0, 2].Value = strValue;
                gcSpread.Sheets[0].Cells[0, 3].Value = 0;
                gcSpread.Sheets[0].Cells[0, 4].Formatter = new GeneralFormatter(FormatMode.CustomMode, "0_);(0)");
                gcSpread.Sheets[0].Cells[0, 4].Formula = "D1-abs(B1)";

    Please, help.


  • Replied 10 September 2017, 10:56 am EST


    In the format "0_);(0)", the "0_)" part is applied to non-negative number values and the "(0)" part is applied to negative number values. String values are displaced as themselves without any special format. This is the same way that Excel works.

    You need to convert the direct values from string values to number values if you want the format "0_);(0)" format applied.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels