使用 Apps 脚本将文本和图像添加到 Google 文档中 table 的特定单元格

Add text and image to specific cell of a table in Google Doc using Apps Script

上下文:我有一个程序可以为 6 至 12 年级的学生创建照片目录,并在 google 文档中创建 leaders/teachers。它为每个学生插入一张图片,然后插入几行单独的文本(姓名、phone 编号等)。在每个新年级开始之前,插入文本以标记年级(即 6 年级)。当过渡到新年级时(即所有 6 年级学生都在目录中,现在从 7 年级学生开始),将启动一个新页面并添加另一个标题来标记新年级(即 7 年级) .我想把它变成一个 3 列目录,页面上每列有 4 个学生。由于 google 文档不允许我直接制作列,我相信我需要制作一个带有 invisible/white 边框的 table。我想让每一页成为 4 行 x 3 列 table。有些年级有超过 12 名学生(一个 4x3 table 的学生),所以我需要继续在某些年级的多个页面上。对于没有 12 名学生的页面,我需要将页面上剩余的单元格留空,或者进行分页,以便新成绩从单独的页面开始。

这里是主要问题:如何 "append" 将图像和段落添加到 table 中的特定单元格?我将如何修改下面的代码,以便将学生的照片和多行信息插入到 table 单元格中,然后启动一个新的 table 单元格?我尝试制作一个 table ,我可以在其中访问每个单元格作为数组的一部分,然后将图像和段落附加到特定单元格,但我无法弄清楚如何(错误代码不包括在下面) .

抱歉代码太长。如果您需要澄清,请告诉我。谢谢!

var sheetID = "x"; //x = link
var GDoc = DocumentApp.openByUrl("y"); //y = link
var body = GDoc.getBody(); //google document body

function loadSheet() {
  body.clear(); //deletes previous doc contents so a new photo directory can be made

//** Variables **//
  //load studentSheet
  var StudentSheet = SpreadsheetApp.openById(sheetID).getSheetByName('Students');
  var studentdata = StudentSheet.getDataRange().getValues();
  var PreviousGrade = "0"; //initially sets the previous grade to zero so that the first grade created will be different than the previous grade
  //make variables to hold data from StudentSheet
  for (var studentRowNumber = 1; studentRowNumber < studentdata.length; studentRowNumber++) { //studentdata.length determines speed of program execution
    var FirstName = studentdata[studentRowNumber][1];
    var LastName = studentdata[studentRowNumber][2];
    var Gender = studentdata[studentRowNumber][3];
    var School = studentdata[studentRowNumber][4];
    var Grade = studentdata[studentRowNumber][5];
    var Birthday = studentdata[studentRowNumber][6];
    var MemberCellPhone = studentdata[studentRowNumber][7]; //student or leader cell phone
    var MemberEmail = studentdata[studentRowNumber][8];
    var DadFirstName = studentdata[studentRowNumber][9];
    var MomFirstName = studentdata[studentRowNumber][10];
    var DadLastName = studentdata[studentRowNumber][11];
    var MomLastName = studentdata[studentRowNumber][12];
    var DadEmail = studentdata[studentRowNumber][13];
    var MomEmail = studentdata[studentRowNumber][14];
    var DadCellPhone = studentdata[studentRowNumber][15];
    var MomCellPhone = studentdata[studentRowNumber][16];
    var HomePhone = studentdata[studentRowNumber][17];
    var StreetAddress = studentdata[studentRowNumber][18];
    var City = studentdata[studentRowNumber][19];
    var ZipCode = studentdata[studentRowNumber][20];  
    var longpictureID = studentdata[studentRowNumber][21];  

/** determines whether a page break should be inserted for a transition to the next grade **/  
    var CurrentGrade = Grade; 
 if (CurrentGrade !== PreviousGrade) { //new grade category
      if (PreviousGrade !== "0") { //this is not the first grade category
        GDoc.appendPageBreak();
      }
      if (PreviousGrade == "0") { //this is the first grade category
        var LittleBlankLine = body.appendParagraph(""); //blank line inserted before first age category title to make things line up evenly on document with columns; modify as needed
      }
      if (CurrentGrade == "6" || CurrentGrade == "7" || CurrentGrade == "8") { //6-8th; || = or
        var GradeCategory = "MS";
        var GradeCategoryTitle = body.appendParagraph(GradeCategory);
        var NewGradeTitle = body.appendParagraph("Grade " + CurrentGrade);
        var BigBlankLine = body.appendParagraph("");
        var SeparationLine = GDoc.appendParagraph("_________________________");
        PreviousGrade = CurrentGrade;
      }
      if (CurrentGrade == "9" || CurrentGrade == "10" || CurrentGrade == "11" || CurrentGrade == "12") { //9-12th
        var GradeCategory = "HS";
        var GradeCategoryTitle = body.appendParagraph(GradeCategory);
        var NewGradeTitle = body.appendParagraph("Grade " + CurrentGrade);
        var BigBlankLine = body.appendParagraph("");
        var SeparationLine = GDoc.appendParagraph("_________________________");
        PreviousGrade = CurrentGrade;
      }
      if (CurrentGrade == "Leader") {
        var GradeCategory = "Youth";
        var GradeCategoryTitle = body.appendParagraph(GradeCategory);
        var NewGradeTitle = body.appendParagraph("Leaders");
        var BigBlankLine = body.appendParagraph("");
        var SeparationLine = GDoc.appendParagraph("_________________________");
        PreviousGrade = CurrentGrade;
      }     
      GradeCategoryTitle.editAsText().setFontSize(36);
      NewGradeTitle.editAsText().setFontSize(36);
      var LittleBlankLine = body.appendParagraph(""); //blank line
      BigBlankLine.editAsText().setFontSize(36);
      SeparationLine.editAsText().setFontSize(7);
 }      


//** Inserting Picture of Student into Google Doc **//
    //verify if there is a picture uploaded for the student, and if there is then insert it in the google doc
    if (longpictureID !== "") { //there is an uploaded picture
      var shortpictureID = longpictureID.replace('https://drive.google.com/uc?export=view&id=', '');
      //(old, new); replace all occurences of old with new in string
    }
      else { //there is not an uploaded picture 
      shortpictureID = "0B5kYlCqpy3BBX2M4M2dWVWEzcjA"; //pic of a silhoutte
      }

      //insert image from drive
         var img = DriveApp.getFileById(shortpictureID).getBlob();
         var inlineI = GDoc.appendImage(img);

         //resizing the image
         var width = inlineI.getWidth();
         var newW = width;
         var height = inlineI.getHeight();
         var newH = height;
         var ratio = width/height;

      //this makes the images all the same height
         newH = 60; 
         newW = parseInt(newH/(1/ratio));
         inlineI.setWidth(newW).setHeight(newH);

//** insert student info into google doc **//
    var FullName = body.appendParagraph(FirstName + " " + LastName); //combine student's first and last names

    //verify that both parents' names are present
    if (DadFirstName == "" && MomFirstName !== "") { 
        //if dad's name is missing
        var ParentsText = body.appendParagraph("Parents: " + MomFirstName);
    }
      else {
        if (DadFirstName !== "" && MomFirstName == "") { 
        //if mom's name is missing
        var ParentsText = body.appendParagraph("Parents: " + DadFirstName);
        }
        else { 
          if (DadFirstName == "" && MomFirstName == "") {
            //if both parent names are missing
            var ParentsText = body.appendParagraph("Parents: ");
          }
          else {
        //both parent names are given   
        var ParentsText = body.appendParagraph("Parents: " + DadFirstName + " & " + MomFirstName);
        }
       }
      }

    //verify that birthday is given
    if (Birthday !== "") { //birthday is given
      var BirthdayText = body.appendParagraph("Birthday: " + Birthday);
    }
    else { //no birthday is given
      var BirthdayText = body.appendParagraph("Birthday: ");
    }

    //verify that grade is given
    if (Grade !== "") {
      if (Grade == "Leader") { //this is a leader
        var GradeText = body.appendParagraph("Role: " + Grade);
      }
      else { //this is a student
    var GradeText = body.appendParagraph("Grade: " + Grade);
      }
    }
    else { //no grade is given
      var GradeText = body.appendParagraph("Grade: ");
      }

    //determine whether this is a student or leader, and if student then verify that both parents' phone numbers are present
    if (Grade == "Leader" && MemberCellPhone !== "") { //this is a leader and he/she has a cellphone
        var CellTextLabel = body.appendParagraph("Phone: "); //label
        var MemberCellText = body.appendParagraph(MemberCellPhone); //leader's cell phone number
        var DadCellText = "";
        var MomCellText = "";
        //extra blank line is added for email
      }
      else { //this is a student
        if (DadCellPhone == "" && MomCellPhone !== "") { 
           //dad's name is missing
           var CellTextLabel = body.appendParagraph("Phone: ");
           var MomCellText = body.appendParagraph("  Mom - " + MomCellPhone);
           var LittleBlankLine = body.appendParagraph(""); //blank line
           var MemberCellText = "";
           var DadCellText = "";
       }
         else {
           if (DadCellPhone !== "" && MomCellPhone == "") { 
           //mom's name is missing
           var CellTextLabel = body.appendParagraph("Phone: ");
           var DadCellText = body.appendParagraph("  Dad - " + DadCellPhone);
           var LittleBlankLine = body.appendParagraph(""); //blank line
           var MemberCellText = "";
           var MomCellText = "";
           }
           else { 
             if (DadCellPhone == "" && MomCellPhone == "") {
               //both parent names are missing
               var CellTextLabel = body.appendParagraph("Phone: None");
               var LittleBlankLine = body.appendParagraph("");
               var LittleBlankLine = body.appendParagraph("");
               var MemberCellText = "";
               var DadCellText = "";
               var MomCellText = "";
           }
             else {
           //both parent names are given   
           var CellTextLabel = body.appendParagraph("Phone: ");
           var DadCellText = body.appendParagraph("  Dad - " + DadCellPhone);
           var MomCellText = body.appendParagraph("  Mom - " + MomCellPhone);
           var MemberCellText = "";
           }
          }
         }
        }

    //verify that both parents' emails are present
    if (Grade == "Leader" && MemberEmail !== "") { //this is a leader and he/she has an email
        var EmailTextLabel = body.appendParagraph("Email: "); //leader's email
        var MemberEmailText = body.appendParagraph("  " + MemberEmail);
        var LittleBlankLine = body.appendParagraph("");
        var LittleBlankLine = body.appendParagraph(""); //extra blank line for leader email, because there is one less blank line for phone
        var DadEmailText = "";
        var MomEmailText = "";
      }
      else { //this is a student
    if (DadEmail == "" && MomEmail !== "") { 
        //dad's name is missing
        var EmailTextLabel = body.appendParagraph("Email: ");
        var MomEmailText = body.appendParagraph("  Mom - " + MomEmail);
        var LittleBlankLine = body.appendParagraph("");
        var DadEmailText = "";
        var MemberEmailText = "";
    }
      else {
        if (DadEmail !== "" && MomEmail == "") { 
        //mom's name is missing
        var EmailTextLabel = body.appendParagraph("Email: ");
        var DadEmailText = body.appendParagraph("  Dad - " + DadEmail);
        var LittleBlankLine = body.appendParagraph("");
        var MomEmailText = "";
        var MemberEmailText = "";
        }
        else { 
          if (DadEmail == "" && MomEmail == "") {
            //both parent names are missing
            var EmailTextLabel = body.appendParagraph("Email: None");
            var LittleBlankLine = body.appendParagraph("");
            var LittleBlankLine = body.appendParagraph("");
            var DadEmailText = "";
            var MomEmailText = "";
            var MemberEmailText = "";
        }
          else {
        //both parent names are given   
        var EmailTextLabel = body.appendParagraph("Email: ");
        var DadEmailText = body.appendParagraph("  Dad - " + DadEmail);
        var MomEmailText = body.appendParagraph("  Mom - " + MomEmail);
        var MemberEmailText = "";
        }
       }
      }
     }

//** modify text attributes **//
    if (FullName !== "") {
    FullName.editAsText().setBold(false).setFontSize(9).setForegroundColor('#000066'); //black
    }

    if (ParentsText !== "") {
      ParentsText.editAsText().setFontSize(7).setForegroundColor(0, 8, '#FF0000'); //red
    }

    if (BirthdayText !== "") {
      BirthdayText.editAsText().setFontSize(7).setForegroundColor(0, 9, '#FF0000');
    }

    if (GradeText !== "") {
      if (Grade == "Leader") { //this is a leader
        GradeText.editAsText().setFontSize(7).setForegroundColor(0, 5, '#FF0000');
      }
      else { //this is a student
    GradeText.editAsText().setFontSize(7).setForegroundColor(0, 6, '#FF0000');
      }
    }

    if (CellTextLabel !== "") {
      CellTextLabel.editAsText().setFontSize(7).setForegroundColor(0, 6, '#FF0000'); //makes first 6 characters red ("Phone:")
    }
    if (MemberCellText !== "") {
      MemberCellText.editAsText().setFontSize(7).setForegroundColor('#000066'); //black
    }
    if (DadCellText !== "") {
      DadCellText.editAsText().setFontSize(7).setForegroundColor('#000066');
    }
    if (MomCellText !== "") {
      MomCellText.editAsText().setFontSize(7).setForegroundColor('#000066');
    }

    if (EmailTextLabel !== "") {
         EmailTextLabel.editAsText().setFontSize(7).setForegroundColor(0, 6, '#FF0000'); //student's email, red
        }
    if (MemberEmailText !== "") {
      MemberEmailText.editAsText().setFontSize(7).setForegroundColor('#000066'); //black
    }
    if (DadEmailText !== "") {
      DadEmailText.editAsText().setFontSize(7).setForegroundColor('#000066');
    }
    if (MomEmailText !== "") {
      MomEmailText.editAsText().setFontSize(7).setForegroundColor('#000066');
    }

    //if (LittleBlankLine !== null) { //not sure if this conditional works
    LittleBlankLine.editAsText().setFontSize(7); 
    //}

    var SeparationLine = GDoc.appendParagraph("_________________________");
    SeparationLine.editAsText().setFontSize(7);
    GDoc.appendParagraph("");
  }
}

我确实找到了解决问题的方法,尽管我不确定它是否是最有效的方法。这是代码,以防对任何人有用:

var sheetID = "x"; //link
var GDoc = DocumentApp.openByUrl("y"); //link
var body = GDoc.getBody(); //google document body
body.clear(); //deletes previous doc contents so a new photo directory can be made

function loadSheet() { 
var CurrentBoxNumber = 1;
var CurrentBox = 1;
//** Variables **//
  //load studentSheet
  var StudentSheet = SpreadsheetApp.openById(sheetID).getSheetByName('Students');
  var studentdata = StudentSheet.getDataRange().getValues();
  var PreviousGrade = "0"; //initially sets the previous grade to zero so that the first grade created will be different than the previous grade
  //make variables to hold data from StudentSheet
  for (var studentRowNumber = 1; studentRowNumber < studentdata.length; studentRowNumber++) { //studentdata.length determines speed of program execution
    var FirstName = studentdata[studentRowNumber][1];
    var LastName = studentdata[studentRowNumber][2];
    var Gender = studentdata[studentRowNumber][3];
    var School = studentdata[studentRowNumber][4];
    var Grade = studentdata[studentRowNumber][5];
    var Birthday = studentdata[studentRowNumber][6];
    var MemberCellPhone = studentdata[studentRowNumber][7]; //student or leader cell phone
    var MemberEmail = studentdata[studentRowNumber][8];
    var DadFirstName = studentdata[studentRowNumber][9];
    var MomFirstName = studentdata[studentRowNumber][10];
    var DadLastName = studentdata[studentRowNumber][11];
    var MomLastName = studentdata[studentRowNumber][12];
    var DadEmail = studentdata[studentRowNumber][13];
    var MomEmail = studentdata[studentRowNumber][14];
    var DadCellPhone = studentdata[studentRowNumber][15];
    var MomCellPhone = studentdata[studentRowNumber][16];
    var HomePhone = studentdata[studentRowNumber][17];
    var StreetAddress = studentdata[studentRowNumber][18];
    var City = studentdata[studentRowNumber][19];
    var ZipCode = studentdata[studentRowNumber][20];  
    var longpictureID = studentdata[studentRowNumber][21];     

/** determines whether a page break should be inserted for a transition to the next grade **/  
    var CurrentGrade = Grade; 
 if (CurrentGrade !== PreviousGrade) { //new grade category
      if (PreviousGrade !== "0") { //this is not the first grade category
        GDoc.appendPageBreak();
        var table = body.appendTable();
        var Row1 = table.appendTableRow();
        var Row1Cell1 = Row1.appendTableCell();
      }
      if (PreviousGrade == "0") { //this is the first grade category
        var table = body.appendTable();
        var Row1 = table.appendTableRow(); 
        var Row1Cell1 = Row1.appendTableCell();
        //var LittleBlankLine = Row1Cell1.appendParagraph(""); //blank line inserted before first age category title to make things line up evenly on document with columns; modify as needed
        //Row1Cell1
      }
      if (CurrentGrade == "6" || CurrentGrade == "7" || CurrentGrade == "8") { //6-8th; || = or
        var GradeCategory = "MS";
        var GradeCategoryTitle = Row1Cell1.appendParagraph(GradeCategory);
        var NewGradeTitle = Row1Cell1.appendParagraph("Grade " + CurrentGrade);
        var BigBlankLine = Row1Cell1.appendParagraph("");
        //var SeparationLine = Row1Cell1.appendParagraph("_________________________");
        PreviousGrade = CurrentGrade;
        CurrentBoxNumber = 2;
      }
      if (CurrentGrade == "9" || CurrentGrade == "10" || CurrentGrade == "11" || CurrentGrade == "12") { //9-12th
        var GradeCategory = "HS";
        var GradeCategoryTitle = Row1Cell1.appendParagraph(GradeCategory);
        var NewGradeTitle = Row1Cell1.appendParagraph("Grade " + CurrentGrade);
        var BigBlankLine = Row1Cell1.appendParagraph("");
        //var SeparationLine = Row1Cell1.appendParagraph("_________________________");
        PreviousGrade = CurrentGrade;
        CurrentBoxNumber = 2;
      }
      if (CurrentGrade == "Leader") {
        var GradeCategory = "Youth";
        var GradeCategoryTitle = Row1Cell1.appendParagraph(GradeCategory);
        var NewGradeTitle = Row1Cell1.appendParagraph("Leaders");
        var BigBlankLine = Row1Cell1.appendParagraph("");
        //var SeparationLine = Row1Cell1.appendParagraph("_________________________");
        PreviousGrade = CurrentGrade;
        CurrentBoxNumber = 2;
      }     
      GradeCategoryTitle.editAsText().setFontSize(36);
      NewGradeTitle.editAsText().setFontSize(36);
      //var LittleBlankLine = Row1Cell1.appendParagraph(""); //blank line
      BigBlankLine.editAsText().setFontSize(7); //36
      //SeparationLine.editAsText().setFontSize(7);
 }      

 /**   1  5  9
       2  6  10
       3  7  11
       4  8  12
 **/
    if (CurrentBoxNumber == 1) {
      var table = body.appendTable();
      var Row1 = table.appendTableRow();
      var Row1Cell1 = Row1.appendTableCell();
      var CurrentBox = Row1Cell1;
      Logger.log(CurrentBox);
    }
    if (CurrentBoxNumber == 2) {
      var Row2 = table.appendTableRow();
      var Row2Cell1 = Row2.appendTableCell();
      var CurrentBox = Row2Cell1;
      Logger.log(CurrentBox);
    }
    if (CurrentBoxNumber == 3) {
      var Row3 = table.appendTableRow();
      var Row3Cell1 = Row3.appendTableCell();
      var CurrentBox = Row3Cell1;
      Logger.log(CurrentBox);
    }
    if (CurrentBoxNumber == 4) {
      var Row4 = table.appendTableRow();
      var Row4Cell1 = Row4.appendTableCell();
      var CurrentBox = Row4Cell1;
      Logger.log(CurrentBox);
    }
    if (CurrentBoxNumber == 5) {
      var Row1Cell2 = Row1.appendTableCell();
      var CurrentBox = Row1Cell2;
      Logger.log(CurrentBox);
    }
    if (CurrentBoxNumber == 6) {
      var Row2Cell2 = Row2.appendTableCell();
      var CurrentBox = Row2Cell2;
      Logger.log(CurrentBox);
    }
    if (CurrentBoxNumber == 7) {
      var Row3Cell2 = Row3.appendTableCell();
      var CurrentBox = Row3Cell2;
      Logger.log(CurrentBox);
    }
    if (CurrentBoxNumber == 8) {
      var Row4Cell2 = Row4.appendTableCell();
      var CurrentBox = Row4Cell2;
      Logger.log(CurrentBox);
    }
    if (CurrentBoxNumber == 9) {
      var Row1Cell3 = Row1.appendTableCell();
      var CurrentBox = Row1Cell3;
      Logger.log(CurrentBox);
    }
    if (CurrentBoxNumber == 10) {
      var Row2Cell3 = Row2.appendTableCell();
      var CurrentBox = Row2Cell3;
      Logger.log(CurrentBox);
    }
    if (CurrentBoxNumber == 11) {
      var Row3Cell3 = Row3.appendTableCell();
      var CurrentBox = Row3Cell3;
      Logger.log(CurrentBox);
    }
    if (CurrentBoxNumber == 12) {
      var Row4Cell3 = Row4.appendTableCell();
      var CurrentBox = Row4Cell3;
      Logger.log(CurrentBox);
    }

//** Inserting Picture of Student into Google Doc **//
    //verify if there is a picture uploaded for the student, and if there is then insert it in the google doc
    if (longpictureID !== "") { //there is an uploaded picture
      var shortpictureID = longpictureID.replace('https://drive.google.com/uc?export=view&id=', '');
      //(old, new); replace all occurences of old with new in string
    }
      else { //there is not an uploaded picture 
      shortpictureID = "0B5kYlCqpy3BBX2M4M2dWVWEzcjA"; //pic of a silhoutte
      }

      //insert image from drive
         var img = DriveApp.getFileById(shortpictureID).getBlob();
         var inlineI = CurrentBox.appendImage(img);

         //resizing the image
         var width = inlineI.getWidth();
         var newW = width;
         var height = inlineI.getHeight();
         var newH = height;
         var ratio = width/height;

      //this makes the images all the same height
         newH = 60; 
         newW = parseInt(newH/(1/ratio));
         inlineI.setWidth(newW).setHeight(newH);

//** insert student info into google doc **//
    var FullName = CurrentBox.appendParagraph(FirstName + " " + LastName); //combine student's first and last names

    //verify that both parents' names are present
    if (DadFirstName == "" && MomFirstName !== "") { 
        //if dad's name is missing
        var ParentsText = CurrentBox.appendParagraph("Parents: " + MomFirstName);
    }
      else {
        if (DadFirstName !== "" && MomFirstName == "") { 
        //if mom's name is missing
        var ParentsText = CurrentBox.appendParagraph("Parents: " + DadFirstName);
        }
        else { 
          if (DadFirstName == "" && MomFirstName == "") {
            //if both parent names are missing
            var ParentsText = CurrentBox.appendParagraph("Parents: ");
          }
          else {
        //both parent names are given   
        var ParentsText = CurrentBox.appendParagraph("Parents: " + DadFirstName + " & " + MomFirstName);
        }
       }
      }

    //verify that birthday is given
    if (Birthday !== "") { //birthday is given
      var BirthdayText = CurrentBox.appendParagraph("Birthday: " + Birthday);
    }
    else { //no birthday is given
      var BirthdayText = CurrentBox.appendParagraph("Birthday: ");
    }

    //verify that grade is given
    if (Grade !== "") {
      if (Grade == "Leader") { //this is a leader
        var GradeText = CurrentBox.appendParagraph("Role: " + Grade);
      }
      else { //this is a student
    var GradeText = CurrentBox.appendParagraph("Grade: " + Grade);
      }
    }
    else { //no grade is given
      var GradeText = CurrentBox.appendParagraph("Grade: ");
      }

    //determine whether this is a student or leader, and if student then verify that both parents' phone numbers are present
    if (Grade == "Leader" && MemberCellPhone !== "") { //this is a leader and he/she has a cellphone
        var CellTextLabel = CurrentBox.appendParagraph("Phone: "); //label
        var MemberCellText = CurrentBox.appendParagraph(MemberCellPhone); //leader's cell phone number
        var DadCellText = "";
        var MomCellText = "";
        //extra blank line is added for email
      }
      else { //this is a student
        if (DadCellPhone == "" && MomCellPhone !== "") { 
           //dad's name is missing
           var CellTextLabel = CurrentBox.appendParagraph("Phone: ");
           var MomCellText = CurrentBox.appendParagraph("  Mom - " + MomCellPhone);
           var LittleBlankLine = CurrentBox.appendParagraph(""); //blank line
           var MemberCellText = "";
           var DadCellText = "";
       }
         else {
           if (DadCellPhone !== "" && MomCellPhone == "") { 
           //mom's name is missing
           var CellTextLabel = CurrentBox.appendParagraph("Phone: ");
           var DadCellText = CurrentBox.appendParagraph("  Dad - " + DadCellPhone);
           var LittleBlankLine = CurrentBox.appendParagraph(""); //blank line
           var MemberCellText = "";
           var MomCellText = "";
           }
           else { 
             if (DadCellPhone == "" && MomCellPhone == "") {
               //both parent names are missing
               var CellTextLabel = CurrentBox.appendParagraph("Phone: None");
               var LittleBlankLine = CurrentBox.appendParagraph("");
               var LittleBlankLine = CurrentBox.appendParagraph("");
               var MemberCellText = "";
               var DadCellText = "";
               var MomCellText = "";
           }
             else {
           //both parent names are given   
           var CellTextLabel = CurrentBox.appendParagraph("Phone: ");
           var DadCellText = CurrentBox.appendParagraph("  Dad - " + DadCellPhone);
           var MomCellText = CurrentBox.appendParagraph("  Mom - " + MomCellPhone);
           var MemberCellText = "";
           }
          }
         }
        }

    //verify that both parents' emails are present
    if (Grade == "Leader" && MemberEmail !== "") { //this is a leader and he/she has an email
        var EmailTextLabel = CurrentBox.appendParagraph("Email: "); //leader's email
        var MemberEmailText = CurrentBox.appendParagraph("  " + MemberEmail);
        var LittleBlankLine = CurrentBox.appendParagraph("");
        var LittleBlankLine = CurrentBox.appendParagraph(""); //extra blank line for leader email, because there is one less blank line for phone
        var DadEmailText = "";
        var MomEmailText = "";
      }
      else { //this is a student
    if (DadEmail == "" && MomEmail !== "") { 
        //dad's name is missing
        var EmailTextLabel = CurrentBox.appendParagraph("Email: ");
        var MomEmailText = CurrentBox.appendParagraph("  Mom - " + MomEmail);
        var LittleBlankLine = CurrentBox.appendParagraph("");
        var DadEmailText = "";
        var MemberEmailText = "";
    }
      else {
        if (DadEmail !== "" && MomEmail == "") { 
        //mom's name is missing
        var EmailTextLabel = CurrentBox.appendParagraph("Email: ");
        var DadEmailText = CurrentBox.appendParagraph("  Dad - " + DadEmail);
        var LittleBlankLine = CurrentBox.appendParagraph("");
        var MomEmailText = "";
        var MemberEmailText = "";
        }
        else { 
          if (DadEmail == "" && MomEmail == "") {
            //both parent names are missing
            var EmailTextLabel = CurrentBox.appendParagraph("Email: None");
            var LittleBlankLine = CurrentBox.appendParagraph("");
            var LittleBlankLine = CurrentBox.appendParagraph("");
            var DadEmailText = "";
            var MomEmailText = "";
            var MemberEmailText = "";
        }
          else {
        //both parent names are given   
        var EmailTextLabel = CurrentBox.appendParagraph("Email: ");
        var DadEmailText = CurrentBox.appendParagraph("  Dad - " + DadEmail);
        var MomEmailText = CurrentBox.appendParagraph("  Mom - " + MomEmail);
        var MemberEmailText = "";
        }
       }
      }
     }

//** modify text attributes **//
    if (FullName !== "") {
    FullName.editAsText().setBold(false).setFontSize(9).setForegroundColor('#000066'); //black
    }

    if (ParentsText !== "") {
      ParentsText.editAsText().setFontSize(7).setForegroundColor(0, 8, '#FF0000'); //red
    }

    if (BirthdayText !== "") {
      BirthdayText.editAsText().setFontSize(7).setForegroundColor(0, 9, '#FF0000');
    }

    if (GradeText !== "") {
      if (Grade == "Leader") { //this is a leader
        GradeText.editAsText().setFontSize(7).setForegroundColor(0, 5, '#FF0000');
      }
      else { //this is a student
    GradeText.editAsText().setFontSize(7).setForegroundColor(0, 6, '#FF0000');
      }
    }

    if (CellTextLabel !== "") {
      CellTextLabel.editAsText().setFontSize(7).setForegroundColor(0, 6, '#FF0000'); //makes first 6 characters red ("Phone:")
    }
    if (MemberCellText !== "") {
      MemberCellText.editAsText().setFontSize(7).setForegroundColor('#000066'); //black
    }
    if (DadCellText !== "") {
      DadCellText.editAsText().setFontSize(7).setForegroundColor('#000066');
    }
    if (MomCellText !== "") {
      MomCellText.editAsText().setFontSize(7).setForegroundColor('#000066');
    }

    if (EmailTextLabel !== "") {
         EmailTextLabel.editAsText().setFontSize(7).setForegroundColor(0, 6, '#FF0000'); //student's email, red
        }
    if (MemberEmailText !== "") {
      MemberEmailText.editAsText().setFontSize(7).setForegroundColor('#000066'); //black
    }
    if (DadEmailText !== "") {
      DadEmailText.editAsText().setFontSize(7).setForegroundColor('#000066');
    }
    if (MomEmailText !== "") {
      MomEmailText.editAsText().setFontSize(7).setForegroundColor('#000066');
    }

    //if (LittleBlankLine !== null) { //not sure if this conditional works
    LittleBlankLine.editAsText().setFontSize(7); 
    //}

    //var SeparationLine = CurrentBox.appendParagraph("_________________________");
    //SeparationLine.editAsText().setFontSize(7);
    //CurrentBox.appendParagraph("");
    table.setBorderColor('#FFFFFF').setBorderWidth(0); //white border

    if (CurrentBoxNumber == 12) {
      CurrentBoxNumber = 1;
    }
    else { //less than 12
      CurrentBoxNumber++;
    }

  }
}