I have a little problem with trigger function on event in Google Apps Script. I try to run my function (in google apps script for spreadsheet) when I write a note in a specific cell. I tried onEdit()
and onChange()
events but neither worked.
Is there a way to trigger those functions when adding a Note to a cell?
I also want to run it when I change font style to italic, bold, or normal.
function onEdit(e) {
var background = false;
var range = e.range;
var cell = range.getCell(1, 1);
var output = cell.getNote();
if(cell.getFontWeight() === 'bold') {
cell.setBackground("#D6F4D9");
background = true;
} else if(cell.getFontWeight() === "normal") {
cell.setBackground("#E4E8F3");
}
if(cell.getFontStyle() === "italic" && !background) {
cell.setBackground("#FCE5CD");
}
if(output != undefined && output != "") {
var numbers = output.split("\n");
var result = 0;
for(var k = 0, leng = numbers.length; k<leng; k++) {
var num = numbers[k];
num = num.split(" ");
if(!isNaN(parseInt(num[0]))) {
result += parseInt(num[0]);
}
if(k >= numbers.length-1) {
if(!isNaN(result)) {
cell.setValue(result+"zł");
}
}
}
}