通过Google表格/应用程序脚本上的自定义菜单提示消息框

时间:2018-02-24 17:18:08

标签: if-statement google-apps-script google-sheets

我在Google表格上创建了​​一个自定义菜单,有两个选项:

function onOpen(e) {
 var menu = SpreadsheetApp.getUi().createMenu('Custom')
 menu.addItem('Add new store', 'openForm')
 menu.addItem('Update Database', 'replacebackenddatabase') }

当用户选择“更新数据库”时,我希望显示一个消息框,并要求确认“是否要继续”和“是/否”。如果用户选择“是”,我希望运行“replacebackenddatabase”功能。如果没有,我只想关闭消息框,没有任何事情发生。

我该怎么做? 谢谢!

2 个答案:

答案 0 :(得分:1)

查看Prompt boxes here



this.props.query.then(...)




答案 1 :(得分:0)

function onOpen(e) {
 var menu = SpreadsheetApp.getUi().createMenu('Custom')
 menu.addItem('Add new store', 'openForm')
 menu.addItem('Update Database', 'checkResponse')
 //.addSeparator()
 //.addSubMenu(SpreadsheetApp.getUi().createMenu('Sub Menu')
 //.addItem('One sub-menu item', 'subFunction1')
 //.addItem('Another sub-menu item', 'subFunction2'))
 .addToUi(); 

// do not set a variable to any chain of methods ending in .addToUi()
// after the Menu is created, the value of menu will be undefined
// the .addToUi() method does not return anything.

 }


function checkResponse() {
  var ui = SpreadsheetApp.getUi();
  var response = ui.alert('Are you sure you want to proceed?', ui.ButtonSet.YES_NO);

  if (response == ui.Button.YES) {
    replacebackenddatabase();
  } else {
    Logger.log("The user wasn't sure.");
  }

}