2012-12-20 19 views
3

我正在撰写Google电子表格的Google应用程序脚本,但遇到一些问题。我尝试通过其值被其他单元格引用的单元格触发“onEdit”函数。但是,它似乎并不好。例如,A单元的值是由B细胞引用(A的值是“=‘B’”),并且如果我改变B细胞的值,A单元将相应地改变,但未能触发onEdit功能的细胞。我在想如果这是因为电子表格自动进行的更改不是触发onEdit函数的事件。如何触发引用单元格的onEdit事件?

有谁知道其他的解决方案来解决这个问题?

在此先感谢!

回答

0

正如你所提到的,onEdit将触发小区B细胞不答:您可以使用它来读出电池的,也可以有一个功能触发每分钟读取单元A

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'); 
    } 
} 
相关问题