SpreadJS Documentation
Convert Expression To Formula
SpreadJS Documentation > Sample Code > Sample Code for Cell References > Convert Expression To Formula

You can convert an expression to formula using the expressionToFormula() method as shown in the code snippet shared below. 

JavaScript
Copy Code

var spread = new GC.Spread.Sheets.Workbook(document.getElementById('ss'), { sheetCount: 1 });
sheet = spread.getSheet(0);
sheet.setValue(0, 0, 1);
sheet.setValue(0, 1, 2);
sheet.setValue(0, 2, 3);
sheet.addCustomName("customName1", "=12", 0, 0);
sheet.addCustomName("customName2", "Average(20,45)", 0, 0);
sheet.addCustomName("customName3", "=$A$1:$C$1");
sheet.setFormula(1, 0, "customName1");
sheet.setFormula(1, 1, "customName2");
sheet.setFormula(1, 2, "sum(customName3)");
var cname = sheet.getCustomName("customName2");
if (cname instanceof GC.Spread.Sheets.NameInfo)

// Get CustomName
    var name = cname.getName();
   

// Get Expression
    var expression = cname.getExpression();
   

 // Get Expression String
    var expStr = GC.Spread.Sheets.CalcEngine.expressionToFormula(sheet, expression, 0, 0);
    console.log("Name: " + name + " ; Expression: " + expStr);
}