Google apps script 在HTML页面中显示Google工作表数据
我有一个谷歌表格,单元格A1和A2中有值。此工作表中还创建了index.html文件。我想在html文件中显示Google工作表中的信息。以下是我所拥有的: 代码G.gs:Google apps script 在HTML页面中显示Google工作表数据,google-apps-script,google-sheets,Google Apps Script,Google Sheets,我有一个谷歌表格,单元格A1和A2中有值。此工作表中还创建了index.html文件。我想在html文件中显示Google工作表中的信息。以下是我所拥有的: 代码G.gs: 函数myFunction(){ var html=HtmlService.createhtmloutpfromfile('index').setSandboxMode(HtmlService.SandboxMode.IFRAME); SpreadsheetApp.getUi().showModalDialog(html,“显
函数myFunction(){
var html=HtmlService.createhtmloutpfromfile('index').setSandboxMode(HtmlService.SandboxMode.IFRAME);
SpreadsheetApp.getUi().showModalDialog(html,“显示工作表数据”);
}
index.html:
函数setPageValues(){
var ss=SpreadsheetApp.getActiveSpreadsheet();
var myFirstValue=ss.getRange(1,1.getValue();
var mySecondValue=ss.getRange(2,1.getValue();
document.getElementById(“first”).innerHTML=myFirstValue;
document.getElementById(“第二”).innerHTML=mySecondValue;
}
来自单元格A的数据:1=
来自单元格A的数据:2=
当我从Google Sheet脚本编辑器运行myFunction时,包含index.html页面的窗口将正确显示。图纸值不存在
我觉得问一些看起来应该很基本的问题很愚蠢,但是。。。“每个人都是某件事的傻瓜”!提前谢谢 下面的修改脚本怎么样?为了使用Google Apps脚本检索和发送数据,您可以使用 代码G.gs: index.html:
函数setPageValues(){
google.script.run.withSuccessHandler(disp.getValuesFroms(“A1:A2”);
}
函数disp(值){
document.getElementById(“first”).innerHTML=值[0][0];
document.getElementById(“second”).innerHTML=值[1][0];
}
来自单元格A的数据:1=
来自单元格A的数据:2=
如果我误解了你的问题,我很抱歉
function myFunction() {
var html = HtmlService.createHtmlOutputFromFile('index').setSandboxMode(HtmlService.SandboxMode.IFRAME);
SpreadsheetApp.getUi().showModalDialog(html, 'Display Sheet Data');
}
function getValuesFromSS(range) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
return ss.getRange(range).getValues();
}
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function setPageValues () {
google.script.run.withSuccessHandler(disp).getValuesFromSS("A1:A2");
}
function disp(values){
document.getElementById("first").innerHTML = values[0][0];
document.getElementById("second").innerHTML = values[1][0];
}
</script>
</head>
<body onload="setPageValues()">
<br>data from cell A:1 = <span id="first"></span>
<br>data from cell A:2 = <span id="second"></span>
</body>
</html>