Reputation: 151
I'm trying to create create an html table from google spreadsheet data.
However I'm not getting success, can someone help.
create the function dynamically according to the data in the spreadsheet
but it keeps giving the error: "Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'."
JS:
function criarTabela(conteudo) {
var tabela = document.createElement("table");
var thead = document.createElement("thead");
var tbody=document.createElement("tbody");
var thd=function(i){return (i==0)?"th":"td";};
for (var i=0;i<conteudo.length;i++) {
var tr = document.createElement("tr");
for(var o=0;o<conteudo[i].length;o++){
var t = document.createElement(thd(i));
var texto=document.createTextNode(conteudo[i][o]);
t.appendChild(texto);
tr.appendChild(t);
}
(i==0)?thead.appendChild(tr):tbody.appendChild(tr);
}
tabela.appendChild(thead);
tabela.appendChild(tbody);
return tabela;
}
document.getElementById("tabela").appendChild(google.script.run.withSuccessHandler(criarTabela).Lista_Aguard_Ajuste());
GS:
function Lista_Aguard_Ajuste(){
var ss = SpreadsheetApp.openByUrl(url);
var ws = ss.getSheetByName("Remanejamento");
var data = ws.getRange(2, 1, ws.getLastRow(), 28).getDisplayValues()
return data;
}
HTML:
<div id="tabela"></div>
Upvotes: 1
Views: 99
Reputation: 201358
I thought that the reason of your issue might be that google.script.run
returns no values. So in your script, how about the following modification?
In this case, please modify criarTabela
in Javascript side.
function criarTabela(conteudo) {
var tabela = document.createElement("table");
var thead = document.createElement("thead");
var tbody=document.createElement("tbody");
var thd=function(i){return (i==0)?"th":"td";};
for (var i=0;i<conteudo.length;i++) {
var tr = document.createElement("tr");
for(var o=0;o<conteudo[i].length;o++){
var t = document.createElement(thd(i));
var texto=document.createTextNode(conteudo[i][o]);
t.appendChild(texto);
tr.appendChild(t);
}
(i==0)?thead.appendChild(tr):tbody.appendChild(tr);
}
tabela.appendChild(thead);
tabela.appendChild(tbody);
document.getElementById("tabela").appendChild(tabela); // Added
}
google.script.run.withSuccessHandler(criarTabela).Lista_Aguard_Ajuste(); // Modified
Lista_Aguard_Ajuste()
in your Google Apps Script works. Please be careful this.Upvotes: 2