【发布时间】:2015-07-28 19:12:22
【问题描述】:
根据第 1 列中输入的数字 2 使该脚本工作的秘诀是什么。我绞尽脑汁地查看 if 语句的条件示例,以各种方式进行调整等。有人会认为我会的我现在已经想通了。但不是。不是这样。是时候利用一些比我更好的大脑了。
function onEdit() {
var s = SpreadsheetApp.getActiveSheet();
if (s.getName() == "Sheet6") { //checks that we're on the correct sheet
var r = s.getActiveCell();
if (r.getColumn() == 1 && r.getColumn.getValue() === '2') { //checks the column
var nextCell = r.offset(0, 1);
nextCell.setValue(new Date());
}
}
}
【问题讨论】:
-
我以前没有使用过 Google 电子表格,但根据代码,每次编辑工作表时,该函数都会运行,查看活动单元格,并将相邻单元格设置为当前日期如果单元格在第 1 列中并且包含值“2”。
-
对,就是这个想法....但由于某种原因它不起作用。调试不会带来任何东西。我认为 getColumn.getValue 部分是错误的。但我不知道正确的写法。
标签: javascript timestamp google-sheets conditional