更改单元格选择时显示警报弹出窗口 (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 服务的运行时才会抛出错误.测试是使用 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屋!