【发布时间】:2021-10-27 16:57:55
【问题描述】:
我有一张 Google 表格 link,其中在 B 列中的单元格输入时,时间戳被放置在 C 列中的单元格中,日期被放置在 G 列中的单元格中。 两个带有新日期的脚本不起作用。日期单元格不允许有时间,因此脚本是:
function onEdit() {
var s = SpreadsheetApp.getActiveSheet();
if( s.getName() == "Guests" ) { //checks that we're on Guests or not
var r = s.getActiveCell();
if( r.getColumn() == 2 ) { //checks that the cell being edited is in column B
var nextCell = r.offset(0,5);
if( nextCell.getValue() === '' ) //checks if the adjacent cell is empty or not?
nextCell.setValue(new Date(new Date().setHours(0,0,0,0))).setNumberFormat('dd/MM/yyyy');
}
}
}
此脚本运行良好,但时间戳脚本不会。
function onEdit() {
var s = SpreadsheetApp.getActiveSheet();
if( s.getName() == "Guests" ) { //checks that we're on Guests or not
var r = s.getActiveCell();
if( r.getColumn() == 2 ) { //checks that the cell being edited is in column B
var nextCell = r.offset(0,1);
if( nextCell.getValue() === '' ) //checks if the adjacent cell is empty or not?
nextCell.setValue(new Date());
}
}
}
我是脚本的彻底失败者。 感谢您的帮助。
【问题讨论】:
标签: date google-sheets timestamp multiple-columns