title: for loop iteration and replaceText
body: <p>I have changed the script to the following:</p>
  
  <pre><code>  function readRows(){
     var nums = ["Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten"];
  
     function toText(num) {
     var s;
     if (num &gt;= 100)
      throw "Too big";
     if (num &gt; 10) {
      if (num &lt; 20) {
          switch (num) {
              case 11:
                  return "Eleven";
              case 12:
                  return "Twelve";
              case 13:
                  return "Thirteen";
              case 14:
                  return "fourteen";
              case 15:
                  return "Fifteen";
              case 16:
                  return "sixteen";
              case 17:
                  return "seventeen";
              case 18:
                  return "eighteen";
              case 19:
                  return "nineteen";
              default:
                  return toText(num-10)+"teen";
          }
      }
  
      switch (Math.floor(num / 10)) {
          case 2:
              s = "Twenty";
              break;
          case 3:
              s = "Thirty";
              break;
          case 4:
              s = "Fourty";
             break;
          case 5:
              s = "Fifty";
              break;
          case 6:
              s= "SiXty";
              break;
          case 7:
              s = "Seventy";
              break;
          default:
              s = toText(Math.floor(num/10))+"ty";
              break;
      }
      if(num &gt; 20 &amp;&amp; num &lt; 30)
         {
          return "twenty"+toText(num-20);
         }
      if(num &gt; 30 &amp;&amp; num &lt; 40)
         {
          return "thirty"+toText(num-30);
         }
      if(num &gt; 40 &amp;&amp; num &lt; 50)
         {
          return "fourty"+toText(num-40);
         }
      if(num &gt; 50 &amp;&amp; num &lt; 60)
         {
          return "fifty"+toText(num-50);
         }
      if(num &gt; 60 &amp;&amp; num &lt; 70)
         {
          return "sixTy"+toText(num-60);
         }
      if(num == 70)
         {
          return "sEvEnty";
         }
      if (num % 10 &gt; 0)
          return s + toText(num % 10);
      return s;
      }
  
      return nums[num];
      }
  
  
      var sheet = SpreadsheetApp.getActiveSheet();
      var lastCol = sheet.getLastColumn();
      var length = sheet.getMaxColumns();
      var rows = sheet.getMaxRows();
  
      var Name = sheet.getRange(2, 2).getValue(); 
      var data = sheet.getRange(2, 1, 2, lastCol);  
      var template = "spreadsheet key";
      var fileName = "Application document template.docx";
      var newFile = DocsList.getFileById(template).makeCopy(Name + " Application for Phase1 NF3").getId();
      var doc = DocumentApp.openById(newFile);
      var body = doc.getActiveSection();
  
      for(var j=1; j&lt;length; j++)
      {
      body.replaceText("Answer"+toText(j), data[0][j]);   // line 105
      }
      }
  </code></pre>
  
  <p>At one stage I had it almost working except for replacing 70, did something and then nothing worked.  Reworked it, now I'm getting this error, 
  TypeError: Cannot read property "1.0" from undefined. (line 105, file "ConvertToDocs").
  Can anyone advise me what the property "1.0" might refer to?  Why is that first line of code not showing in the code window?</p>