更正时间戳脚本.. Quick Q
Correcting timestamp script .. Quick Q
我对脚本还很陌生,所以我只是想让这个脚本为我的 sheet 工作。
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 列中输入时间戳。
我希望时间戳进入 A;除了 nextCell,A 列对应的是什么?
感谢新手问题!
已更新
谢谢!效果很好,也有助于我的理解 :)
如果我希望它应用于多个 sheet 但不是全部。
我尝试添加额外的行,但似乎没有用。我哪里出错了?
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());
}
}
}
function onEdit(e) {
var sheetName = 'Sheet1'; //name of the sheet the script should work on
var colToWatch = 5 // watches for edits made in col E
if (e.range.columnStart !== colToWatch || e.source.getActiveSheet()
.getName() !== sheetName) return;
e.range.offset(0, -4) //offset the currently edited cell by 0 rows, -4 columns
.setValue(e.value ? new Date() : null);
}
看看这对你有用吗?
您的代码使用 offset 方法获取要更新的单元格:
offset(rowOffset, columnOffset)
Returns a new range that is offset from this range by the given number
of rows and columns (which can be negative). The new range will be the
same size as the original range.
因此,如果您想向左写 4 列(A 列)而不是向右写 1 列(F 列),只需替换此行:
var nextCell = r.offset(0, 1);
与:
var nextCell = r.offset(0, -4);
我对脚本还很陌生,所以我只是想让这个脚本为我的 sheet 工作。
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 列中输入时间戳。 我希望时间戳进入 A;除了 nextCell,A 列对应的是什么?
感谢新手问题!
已更新
谢谢!效果很好,也有助于我的理解 :)
如果我希望它应用于多个 sheet 但不是全部。
我尝试添加额外的行,但似乎没有用。我哪里出错了?
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());
}
}
}
function onEdit(e) {
var sheetName = 'Sheet1'; //name of the sheet the script should work on
var colToWatch = 5 // watches for edits made in col E
if (e.range.columnStart !== colToWatch || e.source.getActiveSheet()
.getName() !== sheetName) return;
e.range.offset(0, -4) //offset the currently edited cell by 0 rows, -4 columns
.setValue(e.value ? new Date() : null);
}
看看这对你有用吗?
您的代码使用 offset 方法获取要更新的单元格:
offset(rowOffset, columnOffset)
Returns a new range that is offset from this range by the given number of rows and columns (which can be negative). The new range will be the same size as the original range.
因此,如果您想向左写 4 列(A 列)而不是向右写 1 列(F 列),只需替换此行:
var nextCell = r.offset(0, 1);
与:
var nextCell = r.offset(0, -4);