Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.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
For loop 通过旋转选项进行分析以生成类明细表_For Loop_Google Apps Script_Google Sheets_While Loop - Fatal编程技术网

For loop 通过旋转选项进行分析以生成类明细表

For loop 通过旋转选项进行分析以生成类明细表,for-loop,google-apps-script,google-sheets,while-loop,For Loop,Google Apps Script,Google Sheets,While Loop,我有6张工作表。我使用学生选择生成一系列的4个旋转,学生可以在其中访问课程 表格回复1在D列中列出姓名;列I-N列出了一组六种可能的旋转选择 6Rot1、6Rot2、6Rot3和6Rot4对应于四种可能的旋转 main名册6是一个主名册,用于反映姓名和轮换选择 我试图通过表单响应1进行解析,条件如下: 首先看一下我的专栏,看看是否有“开放点”(我不得不为我糟糕的英语技能道歉。不幸的是,我无法理解实现你目标的逻辑。1.“开放点”是什么(感谢你的帮助)。1.“开放点”指的是该专栏有46个或更少

我有6张工作表。我使用学生选择生成一系列的4个旋转,学生可以在其中访问课程

  • 表格回复1
    在D列中列出姓名;列I-N列出了一组六种可能的旋转选择
  • 6Rot1
    6Rot2
    6Rot3
    6Rot4
    对应于四种可能的旋转
  • main名册6
    是一个主名册,用于反映姓名和轮换选择
我试图通过
表单响应1
进行解析,条件如下:


  • 首先看一下我的专栏,看看是否有“开放点”(我不得不为我糟糕的英语技能道歉。不幸的是,我无法理解实现你目标的逻辑。1.
    “开放点”是什么(感谢你的帮助)。1.“开放点”指的是该专栏有46个或更少的项目(例如,
    6Rot1
    中的C列只有一个标题,因此它有45个开放点;同一工作表中的F列已经有48个项目,因此它没有任何开放点)。2.我要生成的第一个算法检查I列(“第一选择”)
    的表单响应1
    并尝试将该类放入第一个可用的循环中;然后程序循环尝试放置J-N列中的前4个可能选项,直到达到所有4个循环。4.
    表单响应1
    模拟我将使用的输入;另一个…其他工作表构成输出t、 我试图对每一行
    Form Responses 1
    所做的是将人的类“选择”分为四个旋转(
    6Rot1
    6Rot2
    ,等等)。我的代码中的外部
    for loop
    逐行读取
    Form Responses 1
    ,试图把前4个可能的“选择”放进去进入4个轮换。
    mainRoster6
    只是反映了4个轮换工作表中的相同信息(
    6Rot1
    6Rot2
    ,等等)。因为我希望所有4个轮换都有不同的类,所以我已经识别了上面列出的错误:)感谢您的回复。我不得不为我糟糕的英语技能道歉。不幸的是,我仍然看不到您目标的愿景。示例输入值是
    表单响应1
    。示例输出值是
    main roster6
    6Rot1
    6Rot2
    6Rot3
    6Rot4
    。如果我的理解在您的共享电子表格中,在“D”列中有几个
    全名
    的名称是正确的在表单上,响应1分别放在表格
    6Rot1
    6Rot2
    6Rot3
    6Rot4
    的一行中。我无法理解这个逻辑。当名称重复时,我将如何做到这一点?顺便问一下,我在哪里可以看到您在共享电子表格中期望的输入和输出?例如,在您的curr中在ent电子表格中,
    表单响应1
    中的单元格“J2:N2”的值是
    法语I、编码、德语I、艺术7、通信-视频制作
    。在这种情况下,“6Rot1”的“B2”和“E2”是“乔·史密斯”和“彼得·索尔特”。“6Rot2”的“G2”和“I2”是“乔·史密斯”和“彼得·索尔特”。“6Rot3”的“G2”和“I2”是“乔·史密斯”和“比利·基德”“6Rot1”中的“B2”和“D2”分别是“比利·基德”和“乔·史密斯”。我无法理解这种逻辑。我能问一下你吗?
    function myFunction() {
      var mainSheet = SpreadsheetApp.openById('1ki0Cya3IWNwdLIBe0fR1vwfz_ansmfa52NilmdFBrd0');
      var firstRotation = mainSheet.getSheetByName('6Rot1');
      var secondRotation = mainSheet.getSheetByName('6Rot2'); 
      var thirdRotation = mainSheet.getSheetByName('6Rot3');
      var fourthRotation = mainSheet.getSheetByName('6Rot4'); 
    
      var mainRoster = mainSheet.getSheetByName('mainRoster6');
      var responsesSheet = mainSheet.getSheetByName('Form Responses 1');
    
      var destinationCell;
      var column;
      var columnValues;
      var columnContainsStudent;
      var currentSheet;
      var mainRosterLastRow;
      var studentName;
      var compassTeacher;
      var classChoice;
      var rotationCounter;
      var choicesCounter;
      var successCounter; 
    
      var rotationOneSuccess;
      var rotationTwoSuccess;
      var rotationThreeSuccess;
      var rotationFourSuccess;
    
      var responsesLastRow = responsesSheet.getLastRow();
    
      var currentRotationsArray;
    
    //  var y;
      var z;
      for (z = 2; z < responsesLastRow + 1; z++) {
        studentName = responsesSheet.getRange(z, 4).getValues();
        mainRoster.getRange(z, 2).setValue(studentName);
    
        compassTeacher = responsesSheet.getRange(z, 6).getValues();
        mainRoster.getRange(z, 1).setValue(compassTeacher);
    
        choicesCounter = 1;
        successCounter = 0;
        rotationCounter = 1; 
    
        rotationOneSuccess = false;
        rotationTwoSuccess = false;
        rotationThreeSuccess = false;
        rotationFourSuccess = false;
    
        while (choicesCounter < 7) {
    
          if (successCounter > 4) {
            break;
          }
    
          classChoice = responsesSheet.getRange(z, 8 + choicesCounter).getValues();
    
          //test for includes in previous choices
          var currentRotationsArray = mainRoster.getRange(z, 4, 1, 4).getValues();
    
    //      for (y = 0; y < 4; y++) {
    //       if (currentRotationsArray[0][y] == classChoice) {
    //         choicesCounter++;
    //         break;
    //       }
    //      }
    
          while (successCounter < 4) {
    
            if (rotationOneSuccess == false) {
              currentSheet = firstRotation;
            } else if (rotationTwoSuccess == false) {
              currentSheet = secondRotation;
            } else if (rotationThreeSuccess == false) {
              currentSheet = thirdRotation;
            } else {
              currentSheet = fourthRotation;
            }
    
            // Set column number and get values as an array, depending on class choice
            if (classChoice == "Guitar 7") {
              column = 1;
              columnValues = currentSheet.getRange("A1:A").getValues();
            } else if (classChoice == "Communications - Video Production") {
              column = 2;
              columnValues = currentSheet.getRange("B1:B").getValues();
            } else if (classChoice == "Communications - Journalism") {
              column = 3;
              columnValues = currentSheet.getRange("C1:C").getValues();
            } else if (classChoice == "Coding") {
              column = 4;
              columnValues = currentSheet.getRange("D1:D").getValues();
            } else if (classChoice == "Art 7") {
              column = 5;
              columnValues = currentSheet.getRange("E1:E").getValues();
            } else if (classChoice == "Latin I") {
              column = 6;
              columnValues = currentSheet.getRange("F1:F").getValues();
            } else if (classChoice == "Spanish I") {
              column = 7;
              columnValues = currentSheet.getRange("G1:G").getValues();
            } else if (classChoice == "French I") {
              column = 8;
              columnValues = currentSheet.getRange("H1:H").getValues();
            } else {
              column = 9;
              columnValues = currentSheet.getRange("I1:I").getValues();
            }
    
            // Find column's current last row
            var columnLength = columnValues.filter(String).length;
    
            //Add the student to the class's rotation, if the student isn't already there and there's >46 people already in
            if (columnLength < 48) {
              for(var n in columnValues){
                if(columnValues[n][0] == studentName){
                  columnContainsStudent = true;
                  rotationCounter++;
                  break;
                } 
              }
    
              if (columnContainsStudent != true) {
                destinationCell = currentSheet.getRange(columnLength + 1, column);
                destinationCell.setValue(studentName);
    
                if (currentSheet == firstRotation) {
                  rotationOneSuccess = true;
                } else if (currentSheet == secondRotation) {
                  rotationTwoSuccess = true;
                } else if (currentSheet == thirdRotation) {
                  rotationThreeSuccess = true;
                } else {
                  rotationFourSuccess = true;
                }
    
                mainRoster.getRange(z, rotationCounter + 3).setValue(classChoice);
    
                successCounter++;
                rotationCounter++;
                break;
              }  
    
            rotationCounter++; 
            } else { 
              break
            }
    
            rotationCounter++;
          }
    
          choicesCounter++;
    
        } 
      }
    
    }