如何从电子表格中获取数据并将其发送到 html 表 googel 脚本 web

我正在尝试从 google 电子表格数据创建一个 html 表。


但是我没有成功,有人可以帮忙吗?


根据电子表格中的数据动态创建函数


但它一直给出错误:“无法在‘Node’上执行‘appendChild’:参数 1 不是‘Node’类型。”


记者:


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>


翻翻过去那场雪
浏览 95回答 1
1回答

江户川乱折腾

我认为您的问题的原因可能是google.script.run没有返回任何值。那么在你的脚本中,下面的修改怎么样?修改脚本:在这种情况下,请criarTabela在 Javascript 端进行修改。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()在您的 Google Apps 脚本中有效。请注意这一点。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript