Posted 20 November 2022, 4:52 pm EST
Hi team,
I wanna get a list cell have formula in a sheet. Please give me some solution.
Thank and Best regards
Forums Home / Spread / SpreadJS
Posted by: nguyenthanhtuu1995 on 20 November 2022, 4:52 pm EST
Posted 20 November 2022, 4:52 pm EST
Hi team,
I wanna get a list cell have formula in a sheet. Please give me some solution.
Thank and Best regards
Posted 21 November 2022, 10:31 pm EST
Hi,
You could use the toJSON() method to obtain the sheet’s json and iterate through the json’s dataTable to determine whether a cell contains a formula. Please see the following code example:
let activeSheet = spread.getActiveSheet();
let activeSheetJSON = activeSheet.toJSON({ includeBindingSource: true });
let formulasArr = []
let dataTable = activeSheetJSON.data.dataTable;
for (const row in dataTable) {
for (const col in dataTable[row]) {
let data = dataTable[row][col];
if (data.formula) {
formulasArr.push({ row: row, col: col, formula: data.formula });
}
}
}
console.log(formulasArr);
Sample: https://jscodemine.grapecity.com/share/juFT8kWvxkyuKapOYTlwEw/
toJSON method: https://www.grapecity.com/spreadjs/api/classes/GC.Spread.Sheets.Worksheet#tojson
Regards,
Ankit
Posted 22 November 2022, 1:43 pm EST
Thank @ankit.kumar