我有一个Google Sheet,它运行一些Apps Script服务器代码以连接到SQL Server。我想在刷新数据时在模式对话框中显示消息“正在加载...”。我可以弹出模态,但是我想在代码完成后立即自动关闭对话框。
我设置的示例是:
function testpop () {
var htmlOutput = HtmlService
.createHtmlOutput('<p> This box will close when the data has finished loading.</p>')
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setWidth(250)
.setHeight(200);
SpreadsheetApp.getUi().showModalDialog(htmlOutput, 'Loading...');
sleep(1000);
//close the dialog
}
我知道这可以在客户端调用,但需要在GS中进行处理,以便在代码完成后触发。
事件流可能是:
onLoad
模态对话框事件触发客户端代码google.script.run
触发服务器端.gs
功能运行.gs
脚本文件中的服务器功能运行。google.script.host.close();
您将<script>
在模态对话框中需要一个标签。
<script>
window.onload = function() {
//console.log('window.onload ran!');
google.script.run
.withSuccessHandler(closeDialog)
.theFunctionNameToUpdateDatabase()
};
window.closeDialog = function() {
google.script.host.close();
};
</script>
现在您正在使用:
HtmlService.createHtmlOutput(the HTML here)
您可以改用文件创建HTML:
HtmlService.createHtmlOutputFromFile(filename)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句