Google Sheet:如何在 onChange 事件触发时获得实际更改? [英] Google Sheet: How to get the actual change when onChange event fires?

查看:54
本文介绍了Google Sheet:如何在 onChange 事件触发时获得实际更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此事件对象中没有有用的信息.

我不能使用 onEdit 的原因是我使用了一些外部脚本来发布到这个工作表,它不会触发 on edit 事件.

解决方案

使用更改事件对象的 source 属性.

此属性返回活动电子表格,然后您可以使用getActiveSheet()getActiveRange()

函数repondToChange(e){if(e.changeType === '编辑'){const 电子表格 = e.source;常量范围 = 电子表格.getActiveRange();console.log(range.getA1Notation());}}

相关

the doc is not very helpful. Unlike onEdit, onChange event doesn't have a propety that includes the change made. How do I get it?

function onChange(e){
  console.log(e);
} 

There is no useful information in this event object.

The reason I can't use onEdit is I am using some outside script to POST to this sheet and it won't trigger the on edit event.

解决方案

Use the source property of the change event object.

This property returns the active spreadsheet, then you could use getActiveSheet(), getActiveRange() etc.

function repondToChange(e){
  
  if(e.changeType === 'EDIT'){
    const spreadsheet = e.source;
    const range = spreadsheet.getActiveRange();
    console.log(range.getA1Notation());
  }

}

Related

这篇关于Google Sheet:如何在 onChange 事件触发时获得实际更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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