2012-12-20 21 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'); 
    } 
} 
相關問題