onEdit 事件对象访问已修改单元格的先前值? [英] onEdit Event object access to previous value of a cell that has been modified?

查看:29
本文介绍了onEdit 事件对象访问已修改单元格的先前值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到关于 event.source 对象的任何详细文档,所以我想知道是否可以访问修改范围的上一个值,以便我可以比较范围的新值使用范围的旧值进行验证.

I cannot find any detailled documentation on the event.source object so I would like to know if it's possible to access the previous value of the modified range so I can compare the new values of the range with the old values of the range for validation.

感谢您的帮助.

OnEdit(事件)

function onEdit(event) 
/* Default onEdit Event function */
{
  var ssa = SpreadsheetApp.getActiveSpreadsheet();
  var ss = event.source.getActiveSheet();
  var r = event.source.getActiveRange();
...

推荐答案

--edit 现在似乎可以了,请查看下面的链接和评论.

--edit it seems this is now possible, please take look at the links and comments bellow.

有关文档的详细信息此处.

但是之前的值在事件中不可用.有一个关于此的增强请求.您应该为它加星标"以跟踪更新并为它投票.

But the previous value is not available on the event. There's an enhancement request opened regarding this. You should "star" it to keep track of updates and kind of vote for it.

现在,到解决方法".所有这些都基于您必须自己将原始数据保存在其他地方的事实.你可以有一个镜像电子表格或工作表,当任何 onEdit 发生在原件上时,你可以去镜像并获取旧值.这比看起来要复杂一些,因为您还必须通过脚本更新镜像电子表格,但并非电子表格上的所有事件都会触发 onEdit 事件,例如插入行.因此,您的脚本必须更加智能才能跟上那些,这取决于您的使用情况,甚至可能无法实现.

Now, to "workarounds". All of them are based on the fact that you will have to save the original data yourself somewhere else. You can have a mirror spreadsheet or sheet and when any onEdit happens on the original you can go to the mirror and get the old value. This is a little more complicated than it seems, because you'd also have to update the mirror spreadsheet via the script, but not all events on spreadsheet triggers onEdit events, e.g. inserting rows. So your script has to be extra smart to keep up with those, which, depending on your usage, may not even be possible.

这篇关于onEdit 事件对象访问已修改单元格的先前值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆