單擊單元格時的谷歌應用程序腳本分配功能 (google application script assign function when cell is clicked)


問題描述

單擊單元格時的谷歌應用程序腳本分配功能 (google application script assign function when cell is clicked)

Spreadsheet

我正在嘗試在 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:

enter image description here

(by PhilosophistCooper)

參考文件

  1. google application script assign function when cell is clicked (CC BY‑SA 2.5/3.0/4.0)

#scripting #google-sheets #google-sheets-macros #google-apps-script






相關問題

等待進程完成 (Wait for a process to finish)

如何使用 Inno Setup 根據註冊表項選擇在文件夾中安裝插件/文件? (How do I use Inno Setup to optionally install a plugin/file in a folder based on a registry entry?)

Python:遍歷列表但重複一些項目 (Python: Loop through list but repeat some of the items)

Skrip Perl untuk memeriksa server jarak jauh untuk proses (Perl script to check remote server for process)

持續集成中的數據庫變更管理 (Database change management in continuous integration)

如何確定html標籤是否跨多行 (How to determine if an html tag splits across multiple lines)

打開具有特定顏色和標題的 CMD (Open CMD with specific color and title)

用於搜索 XML 文檔的表單 (Form to search XML document)

反編譯 Lua 字節碼的最佳工具? (Best tool(s) for decompiling Lua bytecode?)

如何在 Blender 中通過矩陣反轉變換? (How to reverse a transformation by matrix in Blender?)

在命令行(終端)上使用 R 腳本的最佳方式是什麼? (What's the best way to use R scripts on the command line (terminal)?)

Google Sheets Script,如何創建工作表標籤的新鬆散對象 (Google Sheets Script, how to create a NEW loose object of a sheet tab)







留言討論