Добавьте текст и изображение в определенную ячейку таблицы в Google Doc с помощью Apps Script

Контекст: у меня есть программа, которая создает каталог фотографий для учащихся 6-12 классов и руководителей / учителей в документе Google. Для каждого учащегося вставляется картинка, а затем несколько отдельных строк текста (имя, номер телефона и т. Д.). Перед началом каждой новой оценки вставляется текст для обозначения оценки (т.е. 6-й класс). Когда происходит переход к новому классу (т. Е. Все шестиклассники находятся в каталоге, и теперь он начинается с 7-х классов), запускается новая страница и добавляется другой заголовок, чтобы пометить новый класс (т. Е. 7 класс), Я хочу превратить это в каталог из 3 столбцов с 4 студентами в каждом столбце на странице. Поскольку Google Docs не позволяет мне создавать столбцы напрямую, я считаю, что мне нужно создать таблицу с невидимыми / белыми границами. Я хочу, чтобы каждая страница представляла собой таблицу из 4 строк по 3 столбца. В некоторых классах учится более 12 учеников (один стол 4х3), поэтому мне нужно перейти на несколько страниц для определенных оценок. Для страниц, где нет 12 учеников, мне нужно будет оставить оставшиеся ячейки на странице пустыми или сделать разрыв страницы, чтобы новый класс начинался на отдельной странице.

Вот главный вопрос: как "добавить" изображение и абзацы к определенной ячейке таблицы? Как изменить код, указанный ниже, чтобы фотография ученика и несколько строк информации были вставлены в ячейку таблицы, а затем запущена новая ячейка таблицы? Я попытался создать таблицу, в которой я мог бы получить доступ к каждой ячейке как части массива, а затем добавить изображение и абзацы к определенной ячейке, но я не мог понять, как (этот неисправный код не включен ниже).

Извините за обширный код. Пожалуйста, дайте мне знать, если вам нужны разъяснения. Спасибо!

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("");
  }
}

1 ответ

Решение

На самом деле я нашел решение своей проблемы, хотя я не уверен, является ли оно наиболее эффективным. Вот код, на случай, если он кому-нибудь пригодится:

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++;
    }

  }
}
Другие вопросы по тегам