本文介绍了无法读取属性“长度”从未定义。 (第39行,文件“代码”)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了Google Apps脚本,用于过滤数据并复制到另一个表单。但是,昨天当我今天早上打开时,它显示错误无法从未定义的属性读取长度错误。



onEdt是用户定义的函数。不要与onEdit()比较
$ b $ pre $函数onEdt()
{
var source = SpreadsheetApp。 。getActiveSpreadsheet()getSheetByName( 数据);

var destination = SpreadsheetApp.getActiveSpreadsheet()。getSheetByName(Crunch2);
var data = source.getDataRange()。getValues();
var copydata = new Array(); //这是一个新数组来收集数据
var ldaps = ['ttp','tnh','pamar'];
for(n = 0; n {//在数组中逐行迭代
for(i = 0; i< ldaps.length ; ++ i)
{
if(data [n] [2] == ldaps [i])
{//如果条件为真则将整行复制到目标$ b $如果(数据[n] [0] ==aa)
{
if(data [n] [1] == 41709)
{
if(data (数据[n] [5]!=是)
{
if(data [n] [n] [4]!= - )
{ ] [5]!=UNCERTAIN)
{
if(data [n] [5]!=NO)
{
copydata.push(data [n ]); //复制整行
}
}
}
}
}
}
} // if
} //为
}
//粘贴到另一个sh eet从第一个单元格开始
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);
}


I have written a google Apps Script which is used to filter the data and copy to another sheet. But, Yesterday it was working fine when I open today morning it was showing the error " Cannot read property length from Undefined "

onEdt is a user defined function. Don't compare with 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);
}

Can anybody Please help me with the above issue ?

解决方案

You should add a check for copyData in the last line:

         if (copydata.length) {
             destination.getRange(1,1,copydata.length,copydata[0].length).setValues(copydata);
         }

这篇关于无法读取属性“长度”从未定义。 (第39行,文件“代码”)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-25 04:49