Nic*_*rke 9 google-sheets showmodaldialog google-apps-script
我有一个Google Sheet,它运行一些Apps Script服务器代码以连接到SQL服务器.我想在刷新数据时在模式对话框中显示消息"loading ...".我可以弹出模态,但是我想在代码完成后立即自动关闭对话框.
我设置的一个例子是:
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
}
Run Code Online (Sandbox Code Playgroud)
我知道这可以在客户端调用,但是需要在GS中处理它,以便在代码完成时触发它.
Ala*_*lls 11
事件的流程可能是:
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>
Run Code Online (Sandbox Code Playgroud)
现在你正在使用:
HtmlService.createHtmlOutput(the HTML here)
Run Code Online (Sandbox Code Playgroud)
您可以从文件创建HTML:
HtmlService.createHtmlOutputFromFile(filename)
Run Code Online (Sandbox Code Playgroud)
//显示对话框
var output = HtmlService.createHtmlOutput('<b>Please wait...</b>');
SpreadsheetApp.getUi().showModalDialog(output, 'Saving...');
Run Code Online (Sandbox Code Playgroud)
一些代码
//关闭对话框
var output = HtmlService.createHtmlOutput('<script>google.script.host.close();</script>');
SpreadsheetApp.getUi().showModalDialog(output, 'Loading...');
Run Code Online (Sandbox Code Playgroud)
*可选的
ui.alert("Saved Successfully!")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5006 次 |
| 最近记录: |