Skip to main content

eachCell()

iterates cells in the spreadsheet

eachCell: (cb: (cellName: string, cellValue: any) => any, range?: string) => void;

Parameters:

  • callback: function - a callback function
  • range: string - a range of cells to iterate

Example

spreadsheet.menu.data.add({
id: "validate",
value: "Validate",
items: [
{
id: "isNumber",
value: "Is number"
},
{
id: "isEven",
value: "Is even number"
}
]
});

function checkValue(check) {
spreadsheet.eachCell(function (cell, value) {
if (!check(value)) {
spreadsheet.setStyle(cell, { background: "#e57373" });
} else {
spreadsheet.setStyle(cell, { background: "" });
}
}, spreadsheet.selection.getSelectedCell());
}

spreadsheet.menu.events.on("click", function (id) {
switch (id) {
case "isNumber":
checkValue(function (value) { return !isNaN(value) });
break;
case "isEven":
checkValue(function (value) { return value % 2 === 0 });
break;
}
});

Related sample: Spreadsheet. Menu

If the range of cells is not specified, the method iterates the selected cells.

Related articles

Customization