Google Apps Script / Uncaught TypeError: Cannot read property 'forEach' of null

Google Apps Script / Uncaught TypeError: Cannot read property 'forEach' of null

我正在学习 Google Apps 脚本,我似乎无法自己解决这个问题,所以如果你能在这里帮助我...^_^

下面是我的 html 页面中的代码:

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);

  });
}

我在 .gs 文件中有 getTableData(),它工作正常

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;
}

非常感谢!

不知何故,我通过替换 getValues() 让它工作;与 getDisplayValues(); 我不知道为什么会这样!