簡體   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