![](/img/trans.png)
[英]Using Google Apps Script, can we display a data in the HTML page as soon as somebody enters that data into Google spreadsheet?
[英]How can i load data from a spreadsheet to an html using google apps script?
我正在嘗試將我當前的電子表格中的信息傳遞給我擁有的 HTML 文件,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
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 顯示 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);
}
現在正在發生的事情的視頻
*控制台中的圖片*
getCardById()
中的值用於myname
的變量。如果我的理解是正確的,那么這個修改呢?
不幸的是, google.script.run
沒有返回任何值。 參考所以在這種情況下,請使用withSuccessHandler
如下。 當您的腳本被修改時,請進行如下修改。
var elem = document.getElementById('myLink'),
var myname = google.script.run.getCardById();
elem.href += myname ;
google.script.run.withSuccessHandler(myname => {
var elem = document.getElementById('myLink');
elem.href = myname;
}).getCardById();
如果我誤解了您的問題並且這不是您想要的方向,我深表歉意。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.