Google表格在更改时取得ActiveRange [英] Google Sheets getActiveRange on change

查看:114
本文介绍了Google表格在更改时取得ActiveRange的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个以此为起点的函数

I have a function starting off as such

function onEdit2(e) {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheets()[0];
  // Returns the active cell
  var activeRange = sheet.getActiveRange();

  Logger.log(activeRange.getA1Notation());

我在电子表格中触发了'on change'(它最初是在编辑状态,因此名字,但这并不是通过改变背景颜色来触发的,这对于我在做什么而言是至关重要的)。

I have this function triggered 'on change' in a spreadsheet (it was originally on edit, hence the name, but that isn't triggered by changing background color, which is kinda critical to what I'm doing with this).

这个总是将A1写入记录器,无论我选择哪种电子表格的哪一部分,并且使用getActiveCell来代替getActiveRange。

This always writes A1 to the logger, no matter what part of the spreadsheet I have selected, and it does the same thing with getActiveCell in place of getActiveRange.

有没有办法在脚本运行时获取选定的范围

Is there any way to get the selected range when a script runs?

推荐答案

这是一个严重的缺点触发类型。已经有人提出了一个问题:

This is a serious drawback with this new trigger type. There has already been an issue raised about it:

Issue 2751 :SpreadSheet onChange()触发器

Issue 2751: SpreadSheet onChange() trigger

访问&明星接收更新的问题。由于原始问题已作为增强请求输入,因此触发器不知道更改后的范围这一事实是错误风格的,因此添加您自己的观察值也会有所帮助。

Visit & star the issue to receive updates. It would be helpful to add your own observations as well, since the original issue has been entered as an enhancement request, but the fact that the trigger doesn't know the changed range is bug-flavoured.

这篇关于Google表格在更改时取得ActiveRange的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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