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

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

问题描述

我无法在event.source对象上找到任何详细的文档,所以我想知道是否可以访问修改范围的前一个值,以便我可以比较范围的新值与旧的值范围进行验证。

感谢您的帮助。

OnEdit(event)

/ p>

 函数onEdit(事件)
/ *默认的onEdit事件函数* /
{
var ssa = SpreadsheetApp.getActiveSpreadsheet();
var ss = event.source.getActiveSheet();
var r = event.source.getActiveRange();
...


解决方案

-



有关详细信息,请参阅文档 here



但是之前的值不可用在事件。有关于此的增强功能请求已打开。你应该星它来跟踪更新和投票的类型。



现在,解决方法。所有这些都是基于这样一个事实,即您将不得不将原始数据保存在其他地方。您可以拥有一个镜像电子表格或工作表,当原始文件发生任何 onEdit 时,您可以转到镜像并获取旧值。这看起来有点复杂,因为您还必须通过脚本更新镜像电子表格,但并非电子表格中的所有事件都会触发 onEdit 事件,例如,插入行。因此,您的脚本必须非常聪明才能跟上这些脚步,根据您的使用情况,这可能甚至不可能实现。


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.

Thanks for your help.

OnEdit(event)

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

解决方案

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

Detailed information is on documentation here.

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.

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天全站免登陆