无法从未定义中读取 属性 "length"。 (第 39 行,文件 "Code")
Cannot read property "length" from undefined. (line 39, file "Code")
我写了一个 google Apps 脚本,用于过滤数据并复制到另一个 sheet。但是,昨天它在我今天早上打开时工作正常,它显示错误“无法读取未定义的 属性 长度”
onEdt 是用户定义的函数。不要和onEdit()
比较
function onEdt( )
{
var source = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("data");
var destination = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Crunch2");
var data = source.getDataRange().getValues();
var copydata = new Array();// this is a new array to collect data
var ldaps = [ 'ttp' , 'tnh' , 'pamar' ];
for(n=0;n<data.length;++n)
{ // iterate in the array, row by row
for(i=0;i<ldaps.length;++i)
{
if ( data[n][2]==ldaps[i])
{ // if condition is true copy the whole row to target
if(data[n][0]=="aa")
{
if(data[n][1]==41709)
{
if(data[n][4] != "-")
{
if(data[n][5] != "YES")
{
if(data[n][5] != "UNCERTAIN")
{
if(data[n][5] != "NO")
{
copydata.push(data[n]);// copy the whole row
}
}
}
}
}
}
} //if
}//for
}
//Paste to another sheet from first cell onwards
destination.getRange(1,1,copydata.length,copydata[0].length).setValues(copydata);
}
任何人都可以帮我解决上述问题吗?
您应该在最后一行添加对 copyData 的检查:
if (copydata.length) {
destination.getRange(1,1,copydata.length,copydata[0].length).setValues(copydata);
}
我写了一个 google Apps 脚本,用于过滤数据并复制到另一个 sheet。但是,昨天它在我今天早上打开时工作正常,它显示错误“无法读取未定义的 属性 长度”
onEdt 是用户定义的函数。不要和onEdit()
比较 function onEdt( )
{
var source = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("data");
var destination = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Crunch2");
var data = source.getDataRange().getValues();
var copydata = new Array();// this is a new array to collect data
var ldaps = [ 'ttp' , 'tnh' , 'pamar' ];
for(n=0;n<data.length;++n)
{ // iterate in the array, row by row
for(i=0;i<ldaps.length;++i)
{
if ( data[n][2]==ldaps[i])
{ // if condition is true copy the whole row to target
if(data[n][0]=="aa")
{
if(data[n][1]==41709)
{
if(data[n][4] != "-")
{
if(data[n][5] != "YES")
{
if(data[n][5] != "UNCERTAIN")
{
if(data[n][5] != "NO")
{
copydata.push(data[n]);// copy the whole row
}
}
}
}
}
}
} //if
}//for
}
//Paste to another sheet from first cell onwards
destination.getRange(1,1,copydata.length,copydata[0].length).setValues(copydata);
}
任何人都可以帮我解决上述问题吗?
您应该在最后一行添加对 copyData 的检查:
if (copydata.length) {
destination.getRange(1,1,copydata.length,copydata[0].length).setValues(copydata);
}