【发布时间】:2016-03-03 15:13:38
【问题描述】:
我正在制作一个带有多个工作表标签的大型谷歌电子表格。当我编辑第 6 列时,我需要将时间戳自动输入到第 1 列中。我需要在每张纸上独立发生这种情况。这是我到目前为止的脚本,它运行良好。但是,我将至少再添加 10 个选项卡,我想知道是否有更简单的方法可以做到这一点,而且出错的空间更小。
function onEdit() {
var s = SpreadsheetApp.getActiveSheet();
if( s.getName() == "A" ) { //checks that we're on the correct sheet
var r = s.getActiveCell();
if( r.getColumn() == 6 ) { //checks the column
var nextCell = r.offset(0, -5);
if( nextCell.getValue() === '' ) //is empty?
nextCell.setNumberFormat("MM/dd HH:mm:ss")
nextCell.setValue(new Date());
}
}
if( s.getName() == "B" ) { //checks that we're on the correct sheet
var r = s.getActiveCell();
if( r.getColumn() == 6 ) { //checks the column
var nextCell = r.offset(0, -5);
if( nextCell.getValue() === '' ) //is empty?
nextCell.setNumberFormat("MM/dd HH:mm:ss")
nextCell.setValue(new Date());
}
}
if( s.getName() == "C" ) { //checks that we're on the correct sheet
var r = s.getActiveCell();
if( r.getColumn() == 6 ) { //checks the column
var nextCell = r.offset(0, -5);
if( nextCell.getValue() === '' ) //is empty?
nextCell.setNumberFormat("MM/dd HH:mm:ss")
nextCell.setValue(new Date());
}
}
}
【问题讨论】:
标签: google-apps-script scripting tabs google-sheets timestamp