Get value from formulaBar

Posted by: razeris563 on 24 August 2021, 6:39 am EST

    • Post Options:
    • Link

    Posted 24 August 2021, 6:39 am EST

    Greetings, i have a formulaBar which shows the formula of a currently selected cell. I want to add a key shortcut that would show the formula in the cell aswell. How do I get from SpreadJS the current value inside of formulaBar?

    Thanks a lot!

  • Posted 25 August 2021, 5:53 am EST

    Hi,

    For this, you may create a custom command which performs the same. Please refer to the following code snippet and attached sample that demonstrates the same.

    
      var toggelFormula = {
        canUndo: true,
        execute: function (spread, options, isUndo) {
          var Commands = GC.Spread.Sheets.Commands;
          if (isUndo) {
            Commands.undoTransaction(spread, options);
            return true;
          } else {
            options.cmd = "toggelActiveSheetFormula";
            Commands.startTransaction(spread, options);
            let sheet = spread.getActiveSheet();
            let activeCell = sheet.getCell(
              sheet.getActiveRowIndex(),
              sheet.getActiveColumnIndex()
            );
            if (
              !activeCell.formula() &&
              activeCell.tag() &&
              activeCell.tag().formula
            ) {
              let formula = activeCell.tag().formula;
              activeCell.formula(formula);
              activeCell.tag({ formula: undefined });
            } else if (activeCell.formula()) {
              let formula = activeCell.formula();
              activeCell.formula(null);
              activeCell.text("`=" + formula);
              activeCell.tag({ formula: formula });
            }
    
            Commands.endTransaction(spread, options);
            return true;
          }
        }
      };
      var commandManager = spread.commandManager();
    
      /*113 is the code of f2 key*/
      commandManager.register(
        "toggelActiveSheetFormula",
        toggelFormula,
        113,
        false,
        false,
        false
      );
    
    

    sample: https://codesandbox.io/s/spread-js-starter-forked-8r658?file=/src/index.js:1008-2315

    customAction Demo: https://www.grapecity.com/spreadjs/demos/features/worksheet/actions/custom-action#demo_source_name

    Regards

    Avinash

Need extra support?

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

Learn More

Forum Channels