Detecting formula entered

Posted by: jerome on 26 June 2020, 12:28 am EST

  • Posted 26 June 2020, 12:28 am EST

    Hello, how can i detect every type using (keypress, keydown or keyup) formula inputted in a cell or in formula if its wrong, also the dragging and clicking on a cell during inputing some formulas

    i already try the "GC.Spread.Sheets.Events.SelectionChanged"

    but this events only occur upon clicking the "enter".
  • Marked as Answer

    Replied 29 June 2020, 1:15 am EST

    Hi Jerome,

    You may use the EditChange event for your requirement. Edit change event is fired whenever the value of the cell editor is changed by any means, either by keydown, autocompleting formula, or adding cell references by clicking on cells etc. Please refer to the following code snippet:
    spread.bind(GC.Spread.Sheets.Events.EditChange, function(sender, args) {
    console.log(args.editingText);
    });


    For detecting, if a formula is valid you may use the evaluateFormula method of calcEngine. Please refer to the following code snippet:
    let formula = "=asdfasdf";
    let res = GC.Spread.Sheets.CalcEngine.evaluateFormula(sheet, "=asdfasdf", 0, 0);
    if(res instance of GC.Spread.CalcEngine.CalcError){
    // error in formula
    }else {
    // formula returned correctly
    }


    API references:
    • evaluateFormula Method: https://www.grapecity.com/spreadjs/docs/v13/online/SpreadJS~GC.Spread.Sheets.CalcEngine~evaluateFormula.html
    • EditChange Event: https://www.grapecity.com/spreadjs/docs/v13/online/SpreadJS~GC.Spread.Sheets.Events~EditChange_EV.html

    Regards
  • Replied 30 June 2020, 4:41 am EST

    Nice Thanks!
Need extra support?

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

Learn More

Forum Channels