更改单元格选择时显示警报弹出窗口(onSelectionChange) [英] Show Alert Popup when cell selection is changed (onSelectionChange)
问题描述
我尝试使用新的触发器 onSelectionChange
更改单元格选择时显示警报弹出窗口.由于某种原因,它没有显示任何警报.我是在做错什么,还是警报不适用于此触发器?
I am trying to show an alert popup when cell selection is changed, using the new trigger onSelectionChange
.
For some reason it is not showing any alerts.
Am i doing something wrong or alerts does not work with this trigger?
function onSelectionChange(e) {
showAlert();
}
function showAlert() {
var ui = SpreadsheetApp.getUi();
var result = ui.alert(
'ALERT!',
'ALERT MESSAGE.',
ui.ButtonSet.OK);
}
我也尝试过这种方式:
function onSelectionChange(e) {
var ui = SpreadsheetApp.getUi();
var result = ui.alert(
'ALERT!',
'ALERT MESSAGE.',
ui.ButtonSet.OK);
}
推荐答案
我创建了一个脚本来测试显示弹出"窗口的不同方法.在Google Apps脚本中.在这两个运行时中,只有使用HTML Service的运行时才会引发错误.该测试是使用Chrome(G Suite帐户)完成的,该帐户仅登录了一个帐户.
I created a script to test different ways to show a "pop up" in Google Apps Script. In both runtimes, only the one that use the HTML Service throw an error. The test was done using Chrome, a G Suite account, only signed in in one account.
这是所引用脚本的代码:
Here is the code of the referred script:
function onSelectionChange(e) {
var message = e.range.getA1Notation();
switch(e.range.columnStart){
case 1:
alert(message);
break;
case 2:
toast(message);
break;
case 3:
msgBox(message);
break;
case 4:
dialog(message);
break;
case 5:
alertWithButton(message);
break;
default:
console.info(message);
}
}
function alert(message){
SpreadsheetApp.getUi().alert(message);
}
function toast(message){
SpreadsheetApp.getActiveSpreadsheet().toast(message);
}
function msgBox(message){
Browser.msgBox(message);
}
function dialog(message){
SpreadsheetApp.getUi().showModalDialog(
HtmlService.createHtmlOutput(message),
'Alert'
)
}
function alertWithButton(message){
var ui = SpreadsheetApp.getUi();
ui.alert(message, ui.ButtonSet.OK);
}
这篇关于更改单元格选择时显示警报弹出窗口(onSelectionChange)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!