在'onEdit'函数中,我在此论坛或elswhere中找到的所有示例都包含相同(或类似)的行来定义源,例如:
if( r.getColumn() == 5 ) { //checks updates in column E
我找不到如何调整它,但我希望只有在将列设置为特定值时才会触发onEdit函数:
if value of column E is set to "done" then perform rest of the function
答案 0 :(得分:0)
尝试这样的事情:
function onEdit(e) {
if (e.range.getColumn() === 5 && e.value.toLowerCase() === 'done')
Logger.log('Todo');
}
答案 1 :(得分:0)
我用以下脚本解决了这个问题:
function onEdit() {
var s = SpreadsheetApp.getActiveSheet();
if( s.getName() == "TaskBoard" ) { //checks that we're on the correct sheet; "TaskBoard"
var r = s.getActiveCell();
if( r.getColumn() == 2 ) { //checks updates in column B
var cellContent = r.getValue();
if (cellContent == 'Done')
{
var nextCell = r.offset(0, 4); //offset to same row, and column F; B+4
if( nextCell.getValue() === '' ) //is empty?
{
var time = new Date();
time = Utilities.formatDate(time, "CET", "yyyy-MM-dd");
nextCell.setValue(time);
}
}
};
};
}