简体   繁体   English

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

[英]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.

相关问题 如何使用谷歌表格中的脚本将图像从一个单元格复制到另一个单元格? - How can I use a script in google sheets to copy an image from one cell to another? 在Excel / Google表格中提交表单时复制volatile函数的单元格值 - Copy cell value of volatile function on form submission in Excel/Google Sheets 搜索匹配的单元格,然后将一个单元格复制到 Google 表格中的其他位置 - Search for matching cells then copy one cell to a different location in Google Sheets Google表格可以将一个单元格更改为另一个单元格 - Google Sheets change one cell from another 从单元格自动重命名 Google Sheets 文件 - Renaming Google Sheets File Automatically From A Cell 通过脚本将单元格内容带到 Google Sheets 中的 Notes - Bring cell content to Notes in Google Sheets via script Google 表格宏副本 - Google Sheets Macro Copy 使用3个选择列表中的选项从Google站点中的Google表格返回表格 - Return Table from Google Sheets in Google Sites Using Options from 3 Select Lists 用谷歌表格单元格中的值替换谷歌文档上的值 - Replace a value on google docs with a value from a google sheets cell 从谷歌表格中的 importhtml 生成的单元格中删除 * 符号 - Remove the * symbol from a cell that is generated from importhtml in google sheets
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM