【问题标题】:Auto timestamp and date in multiple columns多列中的自动时间戳和日期
【发布时间】: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


    【解决方案1】:

    已经解决了。

    我使用了时间戳脚本,因为它有日期。格式化单元格以仅显示时间和单元格 G - 日期

    我使用以下方法从时间单元格中提取了这个:

    =TO_DATE(INT(C9))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-01
      • 1970-01-01
      • 2013-06-16
      • 1970-01-01
      相关资源
      最近更新 更多