【发布时间】:2021-04-29 16:18:15
【问题描述】:
我是 Google 应用脚本的新手。
我有 1 个谷歌表,有 2 个标签。我为每个标签页都有一个时间戳脚本。我不知道如何做到这一点,以便如果有人在单元格中键入,时间戳将自动出现。
提前感谢您的帮助。
function onEdit(e){
myFunction1();
myFunction2();
function myFunction1(); {
var row = e.range.getRow();
var col = e.range.getColumn();
if(col === 15 && e.source.getActiveSheet().getName() === "Monthly Reviews" ){
e.source.getActiveSheet().getRange(row,16).setValue(new Date());
}
function myFunction2(); {
var s = SpreadsheetApp.getActiveSheet();
if( s.getName() == "SLP" ) { //checks that we're on "TABNAME" tab or not
var r = s.getActiveCell();
if( r.getRow() == 7 && r.getColumn() == 2 ) { // checks that the cell being edited is in row 7 column
2
var nextCell = r.offset(1, 0); // looks at the cell in the 1 row down same column
if( nextCell.getValue() === '' ) // checks if that adjacent cell (1 down) is empty or not?
nextCell.setValue(new Date()).setNumberFormat('MM-dd-yyyy HH:mm:ss'); //sets the timestamp when
original cell is updated
}
}
}
}
【问题讨论】:
标签: javascript function google-apps-script google-sheets arrow-functions