【问题标题】:Is it possible to update the timestamp when another cell in the same row gets updated?当同一行中的另一个单元格更新时,是否可以更新时间戳?
【发布时间】:2014-11-19 01:45:12
【问题描述】:

我正在使用Google Spreadsheets,我想要做的是每次更新同一行中的单元格时更新Time last Updated 列中包含timestamp 的单元格。

有什么方法可以实现吗?

提前致谢,

【问题讨论】:

    标签: google-sheets


    【解决方案1】:

    未经测试,但这样的东西应该可以工作。由于您没有提供任何详细信息,因此您必须根据需要更改一些变量。

    function onEdit(e) {
    
    var startCol = 2, 
        endCol = 10,
        tsCol = 11, //this is the column where the timestamp will appear
        startRow = 2,
        sheetName = 'Sheet1', //this is the name of the sheet you want the script to work on.
        curSheet = e.source.getActiveSheet();
    //exit script when edits are made another sheet, or in the first row, or before col 2 or after col 10
    if (curSheet.getName() !== sheetName || e.range.columnStart < startCol || e.range.columStart > endCol || e.range.rowStart < startRow) return;
    curSheet.getRange(e.range.rowStart, tsCol)
        .setValue(new Date());
    

    }

    【讨论】:

    • 忘了提一下:根据需要使用时间戳格式化 col:日期、日期/时间或时间。
    猜你喜欢
    • 1970-01-01
    • 2014-05-29
    • 2018-03-23
    • 1970-01-01
    • 1970-01-01
    • 2021-10-16
    • 1970-01-01
    • 2016-12-09
    • 1970-01-01
    相关资源
    最近更新 更多