表格Google脚本 - onEdit和“源代码” [英] Google Scripts for Sheets - onEdit and "source"

查看:230
本文介绍了表格Google脚本 - onEdit和“源代码”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力尝试让脚本工作几天。在其最基本的层次上,我的函数包含这个:

$ p $ function onEdit(e){

var changedRange = e.source.getActiveRange()

}

看起来这是根据Google的文档,这是完全合法的用途: https://developers.google.com/

这段代码会产生这样的错误:

TypeError:无法从undefined读取属性source。 (第18行,文件代码)



我已经为onEdit添加了一个触发器,但这仍然无法在脚本中使用。我错过了什么吗?

解决方案

我创建了一个新电子表格,添加了代码并编辑了一个单元格,并且脚本执行时没有错误。但是,正如JPV在评论中所建议的那样,如果您使用RUN按钮在脚本编辑器内部运行代码,则会产生错误。在编辑器内部运行函数不允许将 e '事件对象传递给该函数。因此,它是未定义


I've been struggling for a few days now trying to get a script to work. At its most basic level my function contains this:

function onEdit(e) {

var changedRange = e.source.getActiveRange()

}

It seems this is a perfectly legitimate use according to Google's docs: https://developers.google.com/apps-script/guides/triggers/events

This code however produces this error:

TypeError: Cannot read property "source" from undefined. (line 18, file "Code")

I've added a trigger for onEdit as well but this still does not work in the script. Am I missing something?

解决方案

I created a new spreadsheet, added your code, and edited a cell, and the script executed with no errors. But, as JPV suggested in the comments, if you run the code inside of the script editor with the RUN button, it will produce an error. Running the function inside of the editor doesn't allow the 'e', event object to be passed into the function. Therefore, it's undefined.

这篇关于表格Google脚本 - onEdit和“源代码”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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