Default Format for cells

Posted by: tushar.thakur on 31 October 2019, 8:57 pm EST

  • Posted 31 October 2019, 8:57 pm EST

    Hi,

    I am from Pearson team and we had raised following query previously

    https://www.grapecity.com/forums/spread-winforms/default-alignment-of-cell-

    We are currently using SpreadJS version 12.2.5

    Now my question is as described below.

    if we do =1/3 in a cell we are getting 0.333333333333333(15 decimal places)

    by default we want it to be 10 decimal places(0.3333333333).

    So is there a way by which we can apply default format for entire spreadsheet while preserving existing cell formats of particular cells?

  • Posted 3 November 2019, 6:04 pm EST

    Hi Tushar,

    We are sorry but with the current API, it is not possible to define a default number formatter to use, hence we have added an enhancement request on your behalf to support this feature. The internal tracking ID for the issue is SJS-2376. We will let you know about any updates regarding the same.

    Regards

    Sharad

  • Posted 7 November 2019, 6:05 pm EST

    Hi Tushar,

    Dev team has informed us that for formulas SJS doesn’t apply any default formatter and the computed result is displayed without any default formatter.

    If you only want to limit the no of digits displayed without changing the underlying data then you could override the default paint method of Base cel type and limit the number of digits as required.

    API method:

    • paint method: https://www.grapecity.com/spreadjs/docs/v13/online/SpreadJS~GC.Spread.Sheets.CellTypes.Base~paint.html

    Also, in v12 sp1, we have enhanced the number and datetime type values to display according to the cell width i.e the no of digits shown will change according to the column’s width.

    Regards

  • Posted 21 November 2019, 10:06 pm EST

    Hi,

    How to apply particular format say 100.12345(5 decimal places) to all cells in the sheet?

    I tried following

    sheet.getCell(2, 2).formatter(“.#####”);

    It works for the cell in second row and second column.

    when I try =1/3 I get 0.33333 but if the column width is reduced I can see #### in the cell value instead of 0.33333

  • Posted 22 November 2019, 2:33 am EST

    Hi,

    How can we set cell type of entire spreadsheet?

    Thanks,

    Tushar

  • Posted 24 November 2019, 5:52 pm EST

    Hi Sharad,

    The example shared in your answer explains how to modify paint method, but how can we apply the newly created cell to entire sheet? this part is not explained there.

  • Posted 24 November 2019, 9:42 pm EST

    when I try =1/3 I get 0.33333 but if the column width is reduced I can see #### in the cell value instead of 0.33333

    This behavior is by design, if the column width is not enough to display the formatted value then “####” is displayed. This behavior is the same as in MS Excel.

    How can we set cell type of entire spreadsheet?

    We could set cell type for the entire spreadsheet by using the setDefaultStyle() method. Please refer to the following code snippet:

    var defaultStyle = new GC.Spread.Sheets.Style();
      defaultStyle.formatter = "0.00";
      defaultStyle.cellType = new GC.Spread.Sheets.CellTypes.CheckBox();
    
      let sheet = spread.getActiveSheet();
      sheet.suspendPaint();
      sheet.setDefaultStyle(defaultStyle);
      sheet.resumePaint();
    

    API refernce:

    • setDefaultStyle Method: https://www.grapecity.com/spreadjs/docs/v13/online/SpreadJS~GC.Spread.Sheets.Worksheet~setDefaultStyle.html

    Regards

Need extra support?

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

Learn More

Forum Channels