Google apps script 正在更正时间戳脚本。。快速Q
我对脚本非常陌生,所以我只是想让这个脚本为我的工作表工作Google apps script 正在更正时间戳脚本。。快速Q,google-apps-script,google-sheets,timestamp,Google Apps Script,Google Sheets,Timestamp,我对脚本非常陌生,所以我只是想让这个脚本为我的工作表工作 function onEdit() { var s = SpreadsheetApp.getActiveSheet(); if( s.getName() == "Sheet1" ) { //checks that we're on the correct sheet var r = s.getActiveCell(); if( r.getColumn() == 5 ) { //checks the column
function onEdit() {
var s = SpreadsheetApp.getActiveSheet();
if( s.getName() == "Sheet1" ) { //checks that we're on the correct sheet
var r = s.getActiveCell();
if( r.getColumn() == 5 ) { //checks the column
var nextCell = r.offset(0, 1);
if( nextCell.getValue() === '' ) //is empty?
nextCell.setValue(new Date());
}
}
}
此时,如果将数据插入到E中,它似乎会在F列中输入一个时间戳。
我想把时间戳放进一个盒子里;与nextCell不同,A列对应的是什么
谢谢你,很抱歉问了我这个新手问题
已更新
谢谢!这非常有效,也有助于我的理解:)
如果我希望这适用于多张图纸,但不是全部
我试着多加几行,但似乎不起作用。。我哪里出错了
function onEdit() {
var s = SpreadsheetApp.getActiveSheet();
if( s.getName() == "Sanshiro" ) { //checks that we're on the correct sheet
var r = s.getActiveCell();
if( r.getColumn() == 5 ) { //checks the column
var nextCell = r.offset(0, -4);
if( nextCell.getValue() === '' ) //is empty?
nextCell.setValue(new Date());
}
if( s.getName() == "Josh" ) { //checks that we're on the correct sheet
var r = s.getActiveCell();
if( r.getColumn() == 5 ) { //checks the column
var nextCell = r.offset(0, -4);
if( nextCell.getValue() === '' ) //is empty?
nextCell.setValue(new Date());
}
if( s.getName() == "Suil" ) { //checks that we're on the correct sheet
var r = s.getActiveCell();
if( r.getColumn() == 5 ) { //checks the column
var nextCell = r.offset(0, -4);
if( nextCell.getValue() === '' ) //is empty?
nextCell.setValue(new Date());
}
}
}
查看这是否适用于您?您的代码使用该方法来获取要更新的单元格:
offset(行偏移、列偏移)
返回一个新范围,该范围与该范围的偏移量为给定的数字
行和列的数目(可以是负数)。新系列将是
与原始范围大小相同
因此,如果要在左侧(A列)写入4列,而不是在右侧(F列)写入一列,只需替换此行:
var nextCell = r.offset(0, 1);
与:
var nextCell = r.offset(0, 1);
var nextCell = r.offset(0, -4);