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