問題描述
單擊單元格時的谷歌應用程序腳本分配功能 (google application script assign function when cell is clicked)
我正在嘗試在 Google 表格電子表格上製作許多按鈕,這些按鈕將以特定於我的交易策略的格式記錄我的加密貨幣交易。該策略的細節對於這個問題並不重要。我只想在單擊(交易!)按鈕時運行相關腳本。我想複製很多,所以為每個買入/賣出範圍製作一個單獨的宏是沒有意義的。解決方案的兩個可能方向對我來說很清楚,但我找不到任何信息。
可能的解決方案 1:選擇單元格後將宏分配給單元格,然後將按鈕放在單元格內。我可以使用 VBA 執行此操作,但找不到有關如何為 Google 表格腳本執行此操作的說明。
可能的解決方案 2:讓函數選擇單擊按鈕下方的相關單元格。相對於其他單元格定位單元格很容易,但我似乎找不到相對於圖像定位單元格的命令。同樣,這在帶有 VBA 的 Excel 中是可行的,但我找不到與 Google Sheets Script 相同的功能。
感謝任何幫助。
相對於其他單元格定位單元格很容易,但我似乎找不到相對於圖像定位單元格的命令。同樣,這在帶有 VBA 的 Excel 中是可行的,但我找不到與 Google Sheets Script 相同的功能。感謝任何幫助。
相對於其他單元格定位單元格很容易,但我似乎找不到相對於圖像定位單元格的命令。同樣,這在帶有 VBA 的 Excel 中是可行的,但我找不到與 Google Sheets Script 相同的功能。感謝任何幫助。
參考解法
方法 1:
You can use checkboxes and this onEdit() code to call whatever function you wish.
function onEdit(e) {
//e.source.toast('Entry');
//Logger.log(JSON.stringify(e));
var sh=e.range.getSheet();
if(sh.getName()=='Trades' && e.range.columnStart==7 && e.range.rowStart>2 && e.value=="TRUE") {
e.range.setValue('FALSE');
e.source.toast('You clicked cell ' + e.range.getA1Notation());
//call whatever function you wish to call
}
}
Animation:
(by Philosophist、Cooper)