我对 Google 脚本编写完全陌生,但我在这里使用了各种帖子来拼凑出我需要的东西:当某个列发生变化时,会向行添加时间戳的东西。这是我目前正在使用的:
function onEdit() {
var s = SpreadsheetApp.getActiveSheet();
if( s.getName() == "test" ) { //checks that we're on the correct sheet
var r = s.getActiveCell();
if( r.getColumn() == 16 ) { //checks the column
var nextCell = r.offset(0, 1);
if( nextCell.getValue() === '' ) //is empty?
nextCell.setValue(new Date());
}
}
}
当我手动更改数据时,这非常有效;但是,脚本正在监视的列从另一张表中提取数据,这无法触发触发器/脚本。我怎样才能解决这个问题,以便带有公式(引用其他工作表)的单元格仍然会触发我的脚本?
非常感谢任何帮助。谢谢!
onEdit 触发器 仅在实际用户编辑电子表格时才起作用。取决于您的用例,但您可以使用时间驱动触发器并将其设置为重复间隔,并使用函数监视列的更改,这是一个示例:
function monitorColumn() {
// Add the trigger from the Resources menu in the Script Editor
// Script Editor > Resources > Current oroject's triggers > Add trigger
}
}