首页 > 解决方案 > 谷歌脚本 CardService.newButtonSet() 越来越空

问题描述

在附加到 Google 电子表格的脚本中,我有一个自定义菜单项来启动/停止脚本。有条件地存储在其他地方的实际状态我想更改提示窗口。一个问题是它似乎CardService.newButtonSet()是空的,所以添加按钮会导致错误。

  var state = true //Comes from DocumentProperties
  var onButton = CardService.newTextButton().setText("Spustit")
  var offButton = CardService.newTextButton().setText("Pozastavit")
  var cancelButton = ui.Button.CANCEL
  var buttonSet

  if (state == "true"){
    msg = "Do you want to stop the scripts?"
    title = "Automatic update is on"
    // Here I get the error: "Cannot find method addButton(Button)"
    buttonSet = CardService.newButtonSet().addButton(offButton).addButton(cancelButton)
  } else if (state == "false"){
    msg = "Do you want allow the scripts"
    title = "Automatic update is off"
    buttonSet = CardService.newButtonSet().addButton(onButton).addButton(cancelButton)
  } else {
    msg = "Do you want to switch automation on or off?"
    title = "Automation"
    buttonSet = CardService.newButtonSet().addButton(onButton).addButton(offButton).addButton(cancelButton)
  }

你有提示,有什么问题吗?

标签: google-apps-scriptgoogle-sheets

解决方案


来自https://developers.google.com/apps-script/reference/card-service/

目前您只能使用此服务来构建 Gmail 插件。


推荐阅读