我尝试添加其他行,以便此时间戳脚本适用于工作表中的多个标签。
如果我将数据输入到表格' Sanshiro'中的col E中,则时间戳有效。 但是,如果在任何其他指定的工作表上输入Col E,则没有任何反应。 有什么需要改变吗?
这是我试图使用它的表格。 https://docs.google.com/spreadsheets/d/1K8QhVKWSsvHTFKDHNv3ySb5bcaU9I7tczIZvIkegbw0/edit#gid=1582815105
提前致谢!!
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());
}
}
}
答案 0 :(得分:0)
我解决了自己的问题,但无论如何都要感谢! 我以为我会为那些也是脚本新手的人发帖。
我没有足够地关闭每个部分} 因此,每张纸的每个部分之后我需要两个}。
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());
} }
if( s.getName() == "Yujiro" ) { //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() == "Martin" ) { //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());
}
}
}
答案 1 :(得分:0)
似乎您的脚本可以简化为:
function onEdit(e) {
var sheets = ["Sanshiro", "Josh", "Suil", "Yujiro", "Martin"];
if (sheets.indexOf(e.source.getActiveSheet()
.getName()) === -1 || e.range.columnStart !== 5) return;
e.range.offset(0, -4)
.setValue(new Date());
}
说明:
希望有帮助吗?