Excel 应用程序脚本不会始终更新google电子表格单元格值
我正在使用html代码创建一个仪表板,用户可以在其中选择一个日期,然后根据选择的日期从远程API获取一些值,然后在工作表中显示这些值 我有类似以下内容的html文件:Excel 应用程序脚本不会始终更新google电子表格单元格值,excel,web-services,google-apps-script,google-api,google-apps,Excel,Web Services,Google Apps Script,Google Api,Google Apps,我正在使用html代码创建一个仪表板,用户可以在其中选择一个日期,然后根据选择的日期从远程API获取一些值,然后在工作表中显示这些值 我有类似以下内容的html文件: <!DOCTYPE html> <html> <head> <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> <script src="//c
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script>
$(function() {
$( "#datepicker" ).datepicker();
});
</script>
</head>
<body>
<form>
<select name="Student" id="category">
<option value="" selected="selected">Select Student</option>
<option value="Abercrombie, Amber">Abercrombie, Amber(Gr 11)</option>
<option value="Yupa, Jason">Yupa, Jason(Gr 9)</option>
</select>
Date: <input type="text" id="datepicker" name="datepicker">
<input type="submit" value="Submit" onclick="myFunction()">
</form>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("category").value;
var x2 = document.getElementById("datepicker").value;
//document.getElementById("demo").innerHTML = x;
google.script.run.functionToRunOnFormSubmit(x, x2);
google.script.host.close();
}
</script>
</body>
</html>
当我从脚本编辑器中选择函数fncopenmydialog时,它会在电子表格上创建一个仪表板,在这里我可以选择日期,但在函数unformsubmit中,我记录参数,然后相应地设置B3和B4单元格值。它没有得到更新,也没有登录到脚本编辑器中。问题是,在调用google.script.run函数(异步ajax调用)之后,您正在调用close 在某些情况下,它甚至可能没有给浏览器足够的时间来启动ajax调用,或者因为页面正在关闭而被取消。因此,有时它可能会到达后端脚本,有时则不会 查看文档,并从中处理成功关闭对话框和失败向用户显示错误 虽然文档没有显式地显示它,但您可以像这样钩住这两个调用:
google.script.run.withFailureHandleronFailure.withSuccessHandleronSuccess.yourCall 不等待上一次调用完成就关闭对话框是不正确的。@ZigMandel好的,你能给我指一下方法的文档吗?关于如何等待第一次调用完成。google for google.script.run
function fncOpenMyDialog() {
//Open a dialog
var htmlDlg = HtmlService.createHtmlOutputFromFile('HTML_myHtml')
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setWidth(500)
.setHeight(300);
SpreadsheetApp.getUi()
.showModalDialog(htmlDlg, 'Dashboard');
};
function functionToRunOnFormSubmit(fromInputForm, datevalue) {
Logger.log(fromInputForm);
Logger.log(datevalue);
SpreadsheetApp.getActiveSheet().getRange('B3').setValue(fromInputForm);
SpreadsheetApp.getActiveSheet().getRange('B4').setValue(datevalue);
};