[英]Copy the content from a Sheets Cell to a Google Sites
I'm using the new Google Sites and I want to display a text box in it, but my goal is to show a text that is written in a cell in a Google sheet.我正在使用新的 Google 协作平台,我想在其中显示一个文本框,但我的目标是显示在 Google 工作表的单元格中写入的文本。 So I can just edit the content in this sheet and it also change in the site.
所以我可以只编辑这张表中的内容,它也会在网站中发生变化。
I've written this code, but it is not working.我已经写了这段代码,但它不起作用。 Someone know what I can do?
有人知道我能做什么吗?
function doGet() {
return HtmlService.createHtmlOutputFromFile('txtSheetToSite');
}
function getText(row, col) {
const ss = SpreadsheetApp.openById("here_goes_the_sheet_id");
const sheet = ss.getSheetByName("Orientacoes");
var row = row;
var col = col;
var value = sheet.getRange(row, col).getValue();
return value;
}
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<script>
function copyTxt(2,1){
var text = google.script.run.getText();
console.log(text);
document.getElementById("titulo").innerText = text;
}
copyTxt();
</script>
</head>
<body>
<div id="titulo"> </div>
</body>
</html>
The code is using google.script.run
the wrong way.代码以错误的方式使用
google.script.run
。 From https://developers.google.com/apps-script/guides/html/reference/run来自https://developers.google.com/apps-script/guides/html/reference/run
Return
返回
void
— this method is asynchronous and does not return directly;void
这个方法是异步的,不直接返回; however, the server-side function can can return a value to the client as a parameter passed to a success handler;但是,服务器端函数可以将值作为传递给成功处理程序的参数返回给客户端; also, return types are subject to the same restrictions as parameter types, except that a form element is not a legal return type
此外,返回类型受与参数类型相同的限制,除了表单元素不是合法的返回类型
Replace代替
function copyTxt(2,1){
var text = google.script.run.getText();
console.log(text);
document.getElementById("titulo").innerText = text;
}
by经过
function copyTxt(){
google.script.run.withSuccessHandler(function(text){
console.log(text);
document.getElementById("titulo").innerText = text;
})
.getText(2,1);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.