3

我正在编写谷歌电子表格的谷歌应用脚​​本,但遇到了一些问题。我尝试通过其值被其他单元格引用的单元格触发“onEdit”函数。但是,它似乎效果不佳。比如A单元格的值被B单元格引用(A的值是“='B'”),如果我改变了B单元格的值,A单元格也会相应改变,但是无法触发onEdit函数一个细胞。我在想是否是因为电子表格自动进行的更改不是会触发 onEdit 函数的事件。

有人知道解决此问题的其他解决方案吗?

提前致谢!

4

2 回答 2

3

onEdit将在单元格更新时运行(如您所假设的)。使用上面的逻辑,是否可以在onEdit事件中设置检查以查看更改了哪些单元格,如果是B,您能否做出更改的逻辑假设A

function onEdit(event)
{
  // 'event' contains information about the edit that took place
  // Here, we read the 'source' and get the active range (our changed cell)
  // We then pull out the string form of the notation to get the cell that changed
  var changedCell= event.source.getActiveRange().getA1Notation();
  Browser.msgBox(changedCell)
  if (changedCell == 'B1') {
    // If the changed cell is the one that affects A, do something
    Browser.msgBox('You changed B1, and this will affect A');
  }
}
于 2012-12-20T15:23:45.297 回答
0

正如您所提到的,onEdit 将针对单元格 B 而不是单元格 A 触发。您可以使用它来读取单元格 A,或者您可以每分钟触发一个函数来读取单元格 A。

于 2012-12-20T08:26:56.283 回答