I'm learning Google Apps Script, and I can't seem to fix this by myself, so if you can help me here... ^_^
Below is the code I have in my html page:
document.addEventListener("DOMContentLoaded",function(){
google.script.run.withSuccessHandler(generateTable).getTableData();
addElement();
});
function generateTable(dataArray){
var tbody = document.getElementById("table-body");
dataArray.forEach(function(r){
var row = document.createElement("tr");
var col1 = document.createElement("td");
col1.textContent = r[0];
var col2 = document.createElement("td");
col2.textContent = r[1];
var col3 = document.createElement("td");
col3.textContent = r[2];
var col4 = document.createElement("td");
col3.textContent = r[3];
var col5 = document.createElement("td");
col3.textContent = r[4];
var col6 = document.createElement("td");
col3.textContent = r[5];
var col7 = document.createElement("td");
col3.textContent = r[6];
var col8 = document.createElement("td");
col3.textContent = r[7];
var col9 = document.createElement("td");
col3.textContent = r[8];
row.appendChild(col1);
row.appendChild(col2);
row.appendChild(col3);
row.appendChild(col4);
row.appendChild(col5);
row.appendChild(col6);
row.appendChild(col7);
row.appendChild(col8);
row.appendChild(col9);
tbody.appendChild(row);
});
}
I have getTableData() in a .gs file and it works fine
function getTableData(){
var ss = SpreadsheetApp.openByUrl(url);
var ws = ss.getSheetByName("Data");
var lr = ws.getLastRow();
var lc = ws.getLastColumn();
var data = ws.getRange(2,1,lr-1,lc).getValues();
Logger.log(data);
return data;
}
Thank you so much!
Somehow, I got it working by replacing getValues(); with getDisplayValues(); I have no idea why this works though!