onEdit()不能捕获所有更改 [英] onEdit() doesn't catch all changes
问题描述
我有这个简单的触发脚本,应该在下一列中添加一个时间戳.很简单,onEdit不会捕获所有编辑. 我可以在设置中做任何事情吗?
I have this simple trigger script that should add a timestamp in the next column. simple, onEdit doesn't catch all edits. Can I do anything in the settings?
function onEdit(e){
if (e.value == "TRUE") {e.range.offset(0, 1).setValue(new Date())}
}
推荐答案
About your situation, there is a thread. In this thread, Rubén says that
这是onEdit的已知限制.
This is a known limitation of onEdit.
关于此问题的直接解决方案,需要等待Google更新.
About the direct solution of this issue, it is required to wait for Google's update.
在这里,我想为您解决一个变通方法.此解决方法的流程如下.
Here, I would like to think of a workaround for your situation. The flow of this workaround is as follows.
此替代方法假设"F1:F20"范围内的复选框处于选中状态.
- 检查已编辑的范围是否在"F1:F20"中.
- 如果编辑的范围在"F1:F20"中,则检索"F1:F20"的值并检查每个值.
- 创建用于放置结果的数组.
- 将创建的数组覆盖为"F1:F20".
通过这种方式,尽管它可能并不完美,但是可以人为地实现.请认为这只是几种解决方法之一.
By this, although it might be not perfect, it can be artificially achieved. Please think of this as just one of several workarounds.
function onEdit(e){
if (e.range.columnStart == 6 && e.range.columnEnd == 6 && e.range.rowStart <= 20) {
var ckeckboxRange = "F1:F20";
var date = new Date();
var range = e.source.getRange(ckeckboxRange);
var values = range.getValues().map(function(e) {return e[0] === true ? [date] : [""]});
range.offset(0, 1).setValues(values);
}
}
结果:
- 这是一个简单的示例脚本.因此,请根据您的情况进行修改.
如果这不是您想要的结果,我表示歉意.
If this was not the result you want, I apologize.
这篇关于onEdit()不能捕获所有更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!