Array Transpose: Error reading property from “Undefined”

心已入冬 提交于 2019-12-11 17:18:09

问题


Getting an error message for the below code that works to get Values from several cells in my order entry tab named POTemplate and log them in my POHistory tab the serves to compile a list of all order detail entries. As the debugger gets to the bottom of the below code, I get an error message stating: "Cannot Read Property 0.0 from Undefined"

function submit() {
  var app = SpreadsheetApp;
  var tplSheet = app.getActiveSpreadsheet().getSheetByName("POTemplate");
  var tplFRow = 22, tplLRow = tplSheet.getLastRow();
  var tplRowsNum = tplLRow - tplFRow + 1;
  var tplFCol = 1, tplLCol = 16;
  var tplColsNum = tplLCol - tplFCol + 1;
  var rangeData = tplSheet.getRange(22, 1, 5, 15).getValues();
  var colIndexes = [0, 3, 10, 12, 15];
  var fData = filterByIndexes(rangeData, colIndexes);
  var target = "POHistory";
  var targetSheet = app.getActiveSpreadsheet().getSheetByName(target);
  var tgtRow = targetSheet.getLastRow() + 1;
  var tgtRowsNum = fData.length - tgtRow + 1;
  var tgtCol = 1;
  var tgtColsNum = fData[0].length - 1 + 1;
  targetSheet.getRange(tgtRow, tgtCol, tgtRowsNum, 
  tgtColsNum).setValues(fData);
}

function filterByIndexes(twoDArr, indexArr) {
  var fData = [];
  twoDArr = twoDArr.transpose();
  for(var i = 0; i < indexArr.length; i++) {
     fData.push(twoDArr[indexArr[i]]);
  }
  return fData.transpose();
}

Array.prototype.transpose = function() {
  var a = this,
      w = a.length ? a.length : 0,
      h = a[0] instanceof Array ? a[0].length : 0;
  if (h === 0 || w === 0) {return [];}
  var i, j, t = [];
  for (i = 0; i < h; i++) {
     t[i] = [];
     for (j = 0; j < w; j++) {
       t[i][j] = a[j][i];
     }
  }
  return t;
}

来源:https://stackoverflow.com/questions/49135491/array-transpose-error-reading-property-from-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!