我正在使用HTML表单在Google电子表格中显示一个对话框,收集两条信息,然后运行一些Google脚本。在该脚本运行之前,我将对话框上的消息更改为“正在运行...”。脚本完成后,我希望消息更改为“ Complete”,但该消息永远不会出现。我认为它可以处理表格。谁能帮我调试一下吗?这是代码:
//Called from custom Menu
var html = HtmlService.createHtmlOutputFromFile('index')
.setWidth(260)
.setHeight(200)
.setSandboxMode(HtmlService.SandboxMode.IFRAME);
SpreadsheetApp.getUi().showModalDialog(html, 'Processing');
//Index.html
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body style="font-family: Arial, Helvetica;font-size:13px">
<div>
<form><b>Please enter the Begin date and End date to use for this date range.</b><br><br>
Begin Date:<br>
<input type="date" id="begindate" name="begindate">
<br><br>End Date:<br>
<input type="date" id="enddate" name="enddate">
<br><br><input type="button" value="OK" id="submitbutton" onmouseup="writeFormData()">
<input type="button" value="Cancel" onclick="google.script.host.close()" />
</form>
</div>
<script>
window.writeFormData = function() {
var beginDate = document.getElementById("begindate").value;
var endDate = document.getElementById("enddate").value;
google.script.run
.withSuccessHandler(dataWasWritten)
.processForm(beginDate, endDate);
};
window.dataWasWritten = function() {
console.log("Function ran.");
};
</script>
function processForm(beginDate, endDate) {
//this works
var html = HtmlService.createHtmlOutputFromFile('working')
.setWidth(260)
.setHeight(200)
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
SpreadsheetApp.getUi().showModalDialog(html, 'Tier Processing');
//Where all the processing is - this works
TierProcessing.New(beginDate, endDate);
//This never shows up!
var html = HtmlService.createHtmlOutputFromFile('done')
.setWidth(260)
.setHeight(200)
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
SpreadsheetApp.getUi().showModalDialog(html, 'Tier Processing');
}
感谢您的帮助!
答案 0 :(得分:0)
尚不清楚工作和完成的html文件是否可以做任何事情,但是似乎不必要地使用了HTML Services。我整理了一个在index.html上具有statusBar的示例,该示例可能完成相同的操作。
function test() {
try {
//Called from custom Menu
var html = HtmlService.createHtmlOutputFromFile('HTML_Test')
.setWidth(260)
.setHeight(220)
.setSandboxMode(HtmlService.SandboxMode.IFRAME);
SpreadsheetApp.getUi().showModalDialog(html, 'Processing');
}
catch(err) {
Logger.log(err);
}
}
function processForm(beginDate, endDate) {
try {
//Where all the processing is - this works
//TierProcessing.New(beginDate, endDate);
sleep(5000);
}
catch(err) {
Logger.log(err);
}
return;
}
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body style="font-family: Arial, Helvetica;font-size:13px">
<div>
<form><b>Please enter the Begin date and End date to use for this date range.</b><br><br>
Begin Date:<br>
<input type="date" id="begindate" name="begindate">
<br><br>End Date:<br>
<input type="date" id="enddate" name="enddate">
<br><br><input type="button" value="OK" id="submitbutton" onclick="writeFormData()">
<input type="button" value="Cancel" onclick="google.script.host.close()" />
</form>
</div>
<div>
<input type="text" id="statusBar" readonly>
</div>
<script>
function writeFormData() {
document.getElementById("statusBar").value = "Working";
var beginDate = document.getElementById("begindate").value;
var endDate = document.getElementById("enddate").value;
google.script.run
.withSuccessHandler(dataWasWritten)
.processForm(beginDate, endDate);
}
function dataWasWritten() {
document.getElementById("statusBar").value = "Function ran";
}
</script>
</body>
</html>