如何在列更改时设置 now()



如果我更改列中的值(A2-A100),我如何设置当前时间戳NOW(),例如A1)。

导入

的是,只要不更改任何内容,时间戳就会保持不变。

为此,您必须使用Google应用脚本。以以下脚本为例:当在 Col A(工作表 1)中进行编辑时,它会"标记"单元格 A1(工作表 1)更改工作表名称,将其粘贴到脚本编辑器中,然后尝试在 col A 中进行一些编辑以查看是否显示图章(根据需要将单元格 A1 格式化为日期或日期/时间)。不要尝试从脚本编辑器运行此脚本。

function onEdit(e) {
var sheetName = 'Sheet1'; //name of the sheet the script should work on 
var colToWatch = 1 // columnn of the edits
var stampCell = 'A1'; 
if (e.range.columnStart !== 1 || e.source.getActiveSheet()
    .getName() !== sheetName || e.range.rowStart ===1) return;
e.source.getActiveSheet()
    .getRange(stampCell)
    .setValue(e.value ? new Date() : null);
 }

最新更新