我是google appscript和Javascript的新手。:)
我想知道为什么在执行时总是出现以下错误?
你们能帮我解决这个问题吗?
谢谢
enter code here
var previousDataRange = ss2.getRange(5,1,lastRow,8);
previousDataRange.clear();
var data = ss.getRange(3,1,lastRow-1,8).getValues();
var currentRow = ss2.getLastRow() + 1;
for (var a = 0 ; a <=data.length ; a++){
for(var b = 0 ; b <=7 ; b++){ // 8 Columns
var cellValue = data[a][b]; //I got the error "typeerror cannot read property '0' of undefined" here
ss2.getRange(currentRow,b+1).setValue(cellValue);
}
currentRow = currentRow + 1;
}
答案 0 :(得分:0)
在数组中,索引从0开始,因此您需要循环到length-1。 用b
做同样的事情
var previousDataRange = ss2.getRange(5,1,lastRow,8);
previousDataRange.clear();
var data = ss.getRange(3,1,lastRow-1,8).getValues();
var currentRow = ss2.getLastRow() + 1;
for (var a = 0 ; a <data.length ; a++){
for(var b = 0 ; b <=7 ; b++){ // 8 Columns
var cellValue = data[a][b]; //I got the error "typeerror cannot read property '0' of undefined" here
ss2.getRange(currentRow,b+1).setValue(cellValue);
}
currentRow = currentRow + 1;
}