有沒有辦法在 Google Apps 腳本中每隔幾秒調用一次函數?

末影密碼

我正在嘗試在谷歌應用程序腳本和工作表中製作一個愚蠢但簡單的小程序,它每隔幾秒鐘就會隨機挑選一個爸爸的笑話向您展示。我嘗試使用 setInterval(),但我發現它不包含在谷歌應用程序腳本中。有什麼建議?

代碼:

  let messageList = ["Where do dads keep their jokes? In a dad-abase!","When does a joke become a dad joke? When it becomes a-parent!","Two men walk into a bar. You'd think the second one would've noticed!","Does your face hurt? 'Cause it's killing me!"]
  function randInt() {
    let listLength = messageList.length
    let random = Math.floor(Math.random() * listLength);
    return random
  }
  function showMessage() {
    let int = randInt()
    console.log(int)
    return messageList[int]
  }
  return showMessage()
}

它會每分鐘從我的列表中隨機選擇一條消息,放入任何具有 =LOL() 的單元格中。

日光J。

在這裡,我找到了Tanaike的解決方案,該解決方案將使用TextFinder更新自定義函數,並將其與時間驅動觸發器相結合,以每分鐘自動刷新一次。

嘗試這個:

代碼:

function LOL(){
  let messageList = ["Where do dads keep their jokes? In a dad-abase!","When does a joke become a dad joke? When it becomes a-parent!","Two men walk into a bar. You'd think the second one would've noticed!","Does your face hurt? 'Cause it's killing me!"]
  let listLength = messageList.length
  let random = Math.floor(Math.random() * listLength);
  return messageList[random];
}

function refresher() {
  const sheet = SpreadsheetApp.getActiveSheet();
  const formula = "=LOL";
  sheet.createTextFinder("^\\" + formula).matchFormulaText(true).useRegularExpression(true).replaceAllWith("Loading");
  sheet.createTextFinder("Loading").matchFormulaText(true).useRegularExpression(true).replaceAllWith(formula);
}

可安裝的觸發器設置:

在此處輸入圖片說明

輸出:

在此處輸入圖片說明

在此處輸入圖片說明

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

有沒有辦法在 Google Apps 腳本中每隔幾秒調用一次自定義函數?

有沒有辦法在 Google Sheet 文檔中整理出雙值?

在反應js中;有沒有辦法在函數內調用導入?

有沒有辦法用吊具解構?

有沒有辦法在 CronJobs 中獲得毫秒?

有沒有辦法模仿 Applescript 中的類?

有沒有辦法在 Vespa 中重用結構

有沒有辦法在文件中添加新行?

有沒有辦法從 Google 表格中的特定顏色編碼行創建 DataFrame?(gspread 和熊貓)

有沒有辦法在公式的確切文本上調用函數?

有沒有辦法使用 C# 在 Visual Studio 中調用現有表單的函數

有沒有辦法在補償漂移的同時每秒調用函數 n 次?

SQL:如果沒有,有沒有辦法計算表中值的數量?

將 Apps 腳本函數應用於 Google 表格中的其他行

有沒有辦法在另一個地圖函數中使用地圖?

有沒有辦法在函數中使用一段可變的代碼?

有沒有辦法列出所有nodejs函數執行時間?

在Ocaml中,有沒有辦法實現棧的pop函數?

有沒有辦法在 dplyr 的 na_if 函數中列出值?

有沒有辦法導出C靜態庫中的函數?

有沒有辦法在類的 init() 函數中設置 elif 語句?

有沒有辦法根據函數中的名稱更改變量的值?

有沒有辦法測試每個函數調用排列,包括默認參數?

有沒有辦法通過 require 包含 esm 腳本?

有沒有辦法在 html 站點上運行多個腳本

有沒有辦法自動獲取對調用構造函數的對象的引用?

有沒有辦法在使用 std::replace 時調用被替換元素的析構函數?

有沒有辦法在函數中使用類似的 gtsummary 表

使用 preventDefault 函數後,有沒有辦法提交此表單?