简体   繁体   English

如何使用谷歌应用程序脚本将数据从电子表格加载到 html?

[英]How can i load data from a spreadsheet to an html using google apps script?

I'm trying to pass information that is in my current SpreadSheet to an HTML file i have, the html was made with google app script, if someone can guide me with this it would be very helpful.我正在尝试将我当前的电子表格中的信息传递给我拥有的 HTML 文件,html 是用谷歌应用程序脚本制作的,如果有人可以指导我这将非常有帮助。 I'm i little bit lost about this我对此有点迷茫

Html Html

<body>
    <!--3.x snippet-->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <!--2.x snippet-->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
    <!--1.x snippet-->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <!-- Source -->
    <!-- Google Hosted Libraries: https://developers.google.com/speed/libraries#jquery -->
  <script>
    window.writeData = function() {
    var userInformation = document.getElementById('form');
    google.script.run.registerUser(userInformation);
  };
  </script>
  <blockquote class="trello-card">
    <a href="" id="myLink">Trello Card</a>
  </blockquote>
  <script src="https://p.trellocdn.com/embed.min.js"></script>
  <script>
    google.script.run.withSuccessHandler(myname => {
    var elem = document.getElementById('myLink');
    elem.href += myname;
    console.log('This is myname:' + myname);
    }).getCardById();
  </script>
</body>

Function that should return the information of the sheet应该返回工作表信息的Function

function getCardById(){
  var app = SpreadsheetApp;
  var activeSp = app.getActiveSpreadsheet();
  var activeSheet = activeSp.getActiveSheet();
  var linkCol = activeSheet.getRange("B2").getValue();
  //Logger.log(' LINKCOL:' + linkCol);
  return linkCol;
}

Function that show the html Function 显示 html

function seeCard() {
 var templateFileId = '1upA3JHioEyxLScebasmsmwXW-SxsiKaPRznKLCKFYhw';
 var sheetName = 'Trello sheet';
 SpreadsheetApp.openById(templateFileId).copy(sheetName);
 var excel =  SpreadsheetApp.create("Probando un html interno a ver ")
 var html = HtmlService.createHtmlOutputFromFile('index') //index is the name of your HTML file
  .setTitle('Trello card')
  .setWidth(300);
   SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
  .showSidebar(html);

}

Video of what is happening right now现在正在发生的事情的视频

video of the problem问题视频

*Picture in the console * *控制台中的图片*

https://www.screencast.com/t/6tHH15yz https://www.screencast.com/t/6tHH15yz

  • You want to use the value from getCardById() to the variable of myname using Google Apps Script and Javascript.您想使用 Google Apps 脚本和 Javascript 将getCardById()中的值用于myname的变量。

If my understanding is correct, how about this modification?如果我的理解是正确的,那么这个修改呢?

Unfortunately, google.script.run doesn't return no values.不幸的是, google.script.run没有返回任何值。 Ref So in this case, please use withSuccessHandler as follows. 参考所以在这种情况下,请使用withSuccessHandler如下。 When your script is modified, please modify as follows.当您的脚本被修改时,请进行如下修改。

From:从:

var elem = document.getElementById('myLink'),
var myname = google.script.run.getCardById(); 
elem.href +=  myname ;

To:至:

google.script.run.withSuccessHandler(myname => {
  var elem = document.getElementById('myLink');
  elem.href = myname;
}).getCardById();

Reference:参考:

If I misunderstood your question and this was not the direction you want, I apologize.如果我误解了您的问题并且这不是您想要的方向,我深表歉意。

暂无
暂无

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

相关问题 使用 Google Apps 脚本,我们可以在有人将数据输入 Google 电子表格后立即在 HTML 页面中显示数据吗? - Using Google Apps Script, can we display a data in the HTML page as soon as somebody enters that data into Google spreadsheet? 谷歌应用程序脚本html选择从电子表格数据加载的选项 - google apps script html select options loaded from spreadsheet data 如何使用Google Apps脚本自动下载Google电子表格数据 - how to automatically download Google spreadsheet data using Google Apps script 使用Google Apps脚本作为服务从电子表格中检索数据 - Using Google Apps Script as service to retrieve data from spreadsheet 如何使用 Google Apps 脚本访问外部电子表格中的数据 - How to access data from an external spreadsheet with Google Apps Script 如何使用谷歌应用脚本将一行从一个谷歌电子表格复制到另一个谷歌电子表格? - How to copy a row from one google spreadsheet to another google spreadsheet using google apps script? Google Apps脚本:如何从一个电子表格中提取今天输入的数据并将其转换为另一电子表格? - Google Apps Script: How do I pull data entered today from one spreadsheet and transpose it to another? 谷歌应用程序脚本 html 到电子表格 - Google apps script html to spreadsheet 如何使用Apps脚本通过电子表格数据自动填充HTML字段? - How to auto populate HTML fields by from Spreadsheet Data using Apps Script? 如何使用Google Apps脚本将特定的行从3个Google电子表格复制到另一个电子表格 - How to copy specific rows from 3 google spreadsheet to another spreadsheet using google apps script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM