将表格单元格中的内容复制到 Google 个站点

Copy the content from a Sheets Cell to a Google Sites

我正在使用 new Google Sites,我想在其中显示一个文本框,但我的目标是显示一个用Google sheet 中的一个单元格。所以我可以只编辑这个 sheet 中的内容,它也会在站点中更改。

我写了这段代码,但它不起作用。有人知道我能做什么吗?

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>

代码使用 google.script.run 的方式有误。来自 https://developers.google.com/apps-script/guides/html/reference/run

Return
void — this method is asynchronous and does not return directly; 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

替换

function copyTxt(2,1){
   var text = google.script.run.getText();
   console.log(text);
   document.getElementById("titulo").innerText = text;
}

来自

function copyTxt(){
   google.script.run.withSuccessHandler(function(text){
     console.log(text);
     document.getElementById("titulo").innerText = text;   
   })
   .getText(2,1);
   
}