gpt4 book ai didi

events - 仅在一列中使用 onEdit

转载 作者:行者123 更新时间:2023-12-01 03:36:04 25 4
gpt4 key购买 nike

我目前正在使用这个脚本:

function onEdit(e)

// Set a comment on the edited cell to indicate when it was changed.
var range = e.range;
range.setNote('Laatst veranderd: ' + new Date());

我需要添加什么才能只在“C”列中起作用?

最佳答案

如果编辑了某个列,则限制代码在 Google 表格中运行。这使用 Apps 脚本 onEdit()保留的函数名称,在编辑事件上触发运行。

获取范围的列号:

function onEdit(e) {//"e" receives the event object
var range = e.range;//The range of cells edited

var columnOfCellEdited = range.getColumn();//Get column number
//Logger.log(columnOfCellEdited)

if (columnOfCellEdited === 3) {// Column 3 is Column C
//Set a comment on the edited cell to indicate when it was changed.
range.setNote('Laatst veranderd: ' + new Date());
};
};

另一个版本:
function onEdit(e) {//"e" receives the event object
var range = e.range;//The range of cells edited

var columnOfCellEdited = range.getColumn();//Get column number
//Logger.log(columnOfCellEdited)


if (columnOfCellEdited !== 3) {return;}// Halt the code if the column
//edited is not column C
//Set a comment on the edited cell to indicate when it was changed.

range.setNote('Laatst veranderd: ' + new Date());

};

关于events - 仅在一列中使用 onEdit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34748462/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com