繁体   English   中英

将表格单元格中的内容复制到 Google 协作平台

[英]Copy the content from a Sheets Cell to a Google Sites

我正在使用新的 Google 协作平台,我想在其中显示一个文本框,但我的目标是显示在 Google 工作表的单元格中写入的文本。 所以我可以只编辑这张表中的内容,它也会在网站中发生变化。

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

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

返回
void这个方法是异步的,不直接返回; 但是,服务器端函数可以将值作为传递给成功处理程序的参数返回给客户端; 此外,返回类型受与参数类型相同的限制,除了表单元素不是合法的返回类型

代替

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);
   
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM