Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/372.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 谷歌脚本失败---类型错误:无法读取属性;“长度”;从未定义_Javascript - Fatal编程技术网

Javascript 谷歌脚本失败---类型错误:无法读取属性;“长度”;从未定义

Javascript 谷歌脚本失败---类型错误:无法读取属性;“长度”;从未定义,javascript,Javascript,我有一个为我编写的google脚本,它已经运行了好几年,现在当我尝试运行它时,我得到了这个错误“TypeError:无法从未定义的文件中读取属性“length”。(第20行,文件…)。程序员不再可以帮助我 脚本的目的是编制一份讲师正在授课的课程列表,并通过电子邮件向他们确认信息是否正确 这里有一个到工作表的链接 这是剧本 //Creating a function to obtain the location of the required columns on the sheet fu

我有一个为我编写的google脚本,它已经运行了好几年,现在当我尝试运行它时,我得到了这个错误“TypeError:无法从未定义的文件中读取属性“length”。(第20行,文件…)。程序员不再可以帮助我

脚本的目的是编制一份讲师正在授课的课程列表,并通过电子邮件向他们确认信息是否正确

这里有一个到工作表的链接

这是剧本

   //Creating a function to obtain the location of the required columns on the sheet
function Columns(){

  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet for Emails");
  var data = sheet.getDataRange().getValues();



  var id = /@/;
  var idRow;
  var len = data.length;

  //Searching for the ID character '@'
  for(i=0; i<len; i++)
  {
    if(id.test(data[i][0]))
    {idRow = i; break;}
  }

  len = data[idRow].length;

  //Going through every column of ID row and matching it to the required columns
  for(i=0; i<len; i++)
  {
    id = data[idRow][i].slice(1); //Slicing off the ID character
    switch(id) //Matching the required columns to the ids
    {
      case '1': this.Instructor = i;break;
      case '2': this.Course = i;break;
      case '3': this.Classroom = i;break;
      case '4': this.Term = i; break;
      case '5': this.Days = i;break;
      case '6': this.Time = i;break;
      case '7': this.CourseID = i;break;
      case '8': this.Dates = i;break;
      case '9': this.InstructorEmail = i;break;
      case '10': this.ExtraSessions = i; break;
      case '11': this.Notes = i; break;
      case '12': this.FolderID = i;break;

    }
  }
}

function AskProfessorRecord(){

  // Opening the required sheet
  var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet for Emails");

  // Getting the range of data
  var range = ss.getDataRange();

  // Getting the values
  var values = range.getValues();

  //Array of Professor Names
  var ProfessorNames = ["Init"];

  // Holds the email id of the professor 
  var ProfessorEmailID;

  //Column Object
  var cols = new Columns();

  var tempName
  var tempIndex

  //** Section Start ** 
  // This section goes through the sheet and creates an array
  // with the all the professors' names
  for(i = 2; i < values.length; i++)
  {
    // Checking the instructor name of the i row
    tempName = values[i][cols.Instructor];

    tempIndex = ProfessorNames.indexOf(tempName);

    if(tempIndex == -1){
      ProfessorNames.push(tempName)
    }
  }
 // ** Section End **

  var html
  var body
  var flag = 0

  var FirstSpaceIndex
  var FirstName



  for(j = 1; j < ProfessorNames.length; j++){
   html = "<DOCTYPE html><html><body>";

    for(i=2; i < values.length; i++){
      if(flag == 0 && values[i][cols.Instructor] == ProfessorNames[j]){
        FirstSpaceIndex = ProfessorNames[j].indexOf(" ");
        FirstName = ProfessorNames[j].slice(0,FirstSpaceIndex)

        body = "Hello "+ FirstName + ",<br><br>" +
               "Media Services is in the process of scheduling class recordings for the next quarter. " + 
               "The classes we have scheduled for you are listed below. " +
               'Please <strong style="color:red;"> check the location and date range</strong> of your class schedule. ' +
               "You only need to respond if there is a modification to the location or dates or if you do not want the classes recorded.<br><br>" 


        flag = 1;
        ProfessorEmailID = values[i][cols.InstructorEmail]; 
      }

     if(flag == 1 && values[i][cols.Instructor] == ProfessorNames[j]){
        body = body + "<br><br>" +
               values[i][cols.Course] + "<br>&emsp;&emsp;" +
               values[i][cols.Term] + "<br>&emsp;&emsp;" +
               values[i][cols.Days] + "<br>&emsp;&emsp;" +
               values[i][cols.Time] + "<br>&emsp;&emsp;" +
               "<strong style='color:red;'>Location: </strong>" +
               values[i][cols.Classroom] + 
               "<br>&emsp;&emsp;" + "<strong style='color:red;'>Date Range: </strong>" +  
               values[i][cols.Dates] +  "<br>&emsp;&emsp;" +
               values[i][cols.CourseID];
      }
    }

    body = body + "<br>-- <br>" + 
           "Joel Bennett <br>" +
           "XYA University <br>" + 
           "Office: 428.222.53338";

    // HTML body is closed
    html = html + body + "</body></html>";

    flag = 0;

    // The email is sent to the professor
    MailApp.sendEmail({
      to: ProfessorEmailID,
      subject: 'Classroom Recording Schedule',
      htmlBody: html });
  }  
}
//创建函数以获取工作表上所需列的位置
函数列(){
var sheet=SpreadsheetApp.getActiveSpreadsheet().getSheetByName(“电子邮件工作表”);
var data=sheet.getDataRange().getValues();
变量id=/@;
var idRow;
var len=data.length;
//正在搜索ID字符“@”

对于(i=0;该错误表示类似
data[idRow]
未定义的
。这意味着预期会找到某些内容,但实际上没有找到。还应该声明索引变量
i
。我对脚本了解很少,您能建议如何修改当前代码以使其正常工作吗?这已得到解决。我添加了一个破坏脚本的列。