我正在为我的Google表格构建一个用户界面,我编写了我的.gs函数,它返回了我想要的值。我还编写了HTML对话框,显示了我需要的窗口。
我知道如何使用静态文本填充对话框,但我不知道如何将.gs函数返回的值放在对话框中打印出来。
HTML
<html>
<head>
<base target="_top">
</head>
<body>
I want to have the value returned from the .gs function visible here as text.
<select id="simple" name="simple">
<option> or even better here </option>
<option>another option</option>
<option>yet another option</option>
</select>
</body>
</html>
GS
function getCellContent() {
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("MySheet");
var value = ss.getRange('A2').getValue();
return value;
};
我觉得我已经阅读了整个互联网,并没有发现任何关于这些基本的东西。
您可以使用scriplets将值打印到HTML中。例如
<html>
<body>
<h1> Cell content: </h1>
<p> <?= getCellContent() ?> </p>
</body>
</html>
解决方案是在代码之外,我已经附上了。
还有另一个功能可以在屏幕上显示窗口。在我之前的代码中它是:
.GS
var html = HtmlService.createHtmlOutputFromFile('Index');
但是正确地看起来应该是这样的:
var html = HtmlService.createTemplateFromFile('Index').evaluate();
谢谢你的耐心。