【发布时间】:2019-06-02 19:25:31
【问题描述】:
我正在尝试在此代码中添加另一行代码,以使“绿色”单元格在给定时间后切换回“黄色”。我会添加另一个函数还是添加另一个 else 语句?是否可以再嵌套一次 utility.sleep 函数,并且仅在满足大于条件时才触发它?
此外,如果我希望它跨越而不是列并精确定位代表表格的特定单元格。想一想有她的座位表的女主人,这可以在行的偏移子句中完成。并且此代码是否也可以在另一张纸上运行,并且在颜色更改和时间戳在另一张纸上运行时仅向女主人显示复选框?
现在我创建了一个仅满足 2 个条件的时间戳。在一定时间后,未单击变为绿色并单击变为红色。如果我需要创建另一个函数,我将同时运行这两个函数,或者我只是在当前函数中添加更多 var 以包括满足我的绿色到黄色的第三个条件,显示一个准备就座的 stag-net 桌子,而红色显示他们有已经在餐桌上很久了,但它仍然被占用
function onEdit(e) {
var s = SpreadsheetApp.getActiveSheet(); // the active sheet (no need to check if the sheet == sheet1 as the active sheet will always be the one that's being edited)
var r = e.range; // the range of the edited cell
var c = r.getColumn(); // the column of the range
var timeDelay = 5; // number in seconds
var checkbox = r.getValue(); // the value of the checkbox after being
edited
var date = new Date(); // the date for the timestamp
if (c == 3 && checkbox === true) { // if the checkbox has been checked,
change the color to red
var nextCell = r.offset(0,1);
Utilities.sleep(timeDelay * 100); // Utilities.sleep takes a number in
milliseconds
nextCell.setValue(date).setBackground("red");
} else if (c == 3 && checkbox === false){ // unchecked switch to green
var nextCell = r.offset(0,1);
nextCell.setValue(date).setBackground("green");
Utilities.sleep(timeDelay * 1);
}
}
每当我尝试添加另一个 else 语句时,我不能,如果我向绿色添加另一个条件,否则如果让它在 x 分钟后变为黄色,它会跳过变为绿色并直接变为黄色而不是在两者之间摇摆不定
【问题讨论】:
-
“我尝试添加另一个我不能添加的 else 语句”是什么意思?
-
在该函数中添加另一个 else 语句以提供代码以在单元格空闲且未被占用时返回黄色,也就是在 x 分钟内未选中复选框,将绿色变为黄色
标签: javascript if-statement google-apps-script google-sheets