我在Google表格上创建了一个自定义菜单,有两个选项:
function onOpen(e) {
var menu = SpreadsheetApp.getUi().createMenu('Custom')
menu.addItem('Add new store', 'openForm')
menu.addItem('Update Database', 'replacebackenddatabase') }
当用户选择“更新数据库”时,我希望显示一个消息框,并要求确认“是否要继续”和“是/否”。如果用户选择“是”,我希望运行“replacebackenddatabase”功能。如果没有,我只想关闭消息框,没有任何事情发生。
我该怎么做? 谢谢!
答案 0 :(得分:1)
答案 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.");
}
}