Posted 26 February 2026, 12:16 am EST
Using SpreadJS, I am validating formula strings entered by users in a form by using the formulaToExpression method.
// Parse formulas
const formulas = [
'=1+2',
'=1+2+',
'=1+2-',
'=1+2++',
'=1+2*',
];
for (const formula of formulas) {
try {
const expression = GC.Spread.Sheets.CalcEngine.formulaToExpression(null, formula);
const normalized = GC.Spread.Sheets.CalcEngine.expressionToFormula(null, expression);
console.log(`${formula}: OK (${normalized})`);
}
catch (error) {
console.log(`${formula}: ${error}`);
}
}
The results of testing several formulas are as follows:
=1+2: OK (1+2)
=1+2+: OK (1+2)
=1+2-: OK (1+2)
=1+2++: Invalid Formula
=1+2*: Invalid Formula
=1+2+ and =1+2- are invalid formulas (they are not accepted by Microsoft Excel), but SpreadJS returns OK.
Is this the correct behavior?
