我在尝试解决方案,我正试图将一个变量从Google Script传递到HtmlOutputFromFile,但无法使其工作。我收到错误(从荷兰语翻译而来(:"TypeError:在对象HtmlService.中找不到函数createHtmlTemplateFromFile
function fncOpenMyDialog() {
//Open a dialog
var htmlDlg = HtmlService.createHtmlTemplateFromFile('DropDown_NewCompetitionFile');
htmlDlg.myVar = "November";
htmlDlg = htmlDlg.evaluate()
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setWidth(200)
.setHeight(150);
SpreadsheetApp.getUi()
.showModalDialog(htmlDlg, 'A Title Goes Here');
};
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<select name="nameYouWant">
<option value="something">Text</option>
<option value="anything">Drop Down Selection</option>
<option value="anotherthing"><?myVar?></option>
</select>
<hr/>
<ul>
<li>This is a list.</li>
<li>This is line two.</li>
</ul>
<button onmouseup="closeDia()">Close</button>
<script>
window.closeDia = function() {
google.script.host.close();
};
</script>
</body>
</html>
更换
HtmlService.createHtmlTemplateFromFile
带有
HtmlService.createTemplateFromFile
你可以随心所欲,但这似乎简单得多:
<input type="button" value="Close" onClick="google.script.host.close()" />
比这个:
<button onmouseup="closeDia()">Close</button>
<script>
window.closeDia = function() {
google.script.host.close();
};
</script>
我更喜欢在window.onload
上通过javascript加载我的选择选项