title: Modify a table from script in Google Docs
body: <p>I have a Google Doc containing one table. I'm trying to write a script that appends a number of empty rows to a table, how can I do that?</p>
  
  <p>I've tried with the following function:</p>
  
  <pre><code>function insertRows2() {
    var NUMBER_OF_ROWS = 40;
  
    var body = DocumentApp.getActiveDocument().getBody(),
        searchElement = body.findElement(DocumentApp.ElementType.TABLE),
        element = searchElement.getElement(),
        table = element.asTable();
  
    Logger.log('num rows: ' + table.getNumRows());
  
    for (var i = 0; i &lt; NUMBER_OF_ROWS; i++) {
      table.appendTableRow();
    }
  
    Logger.log('num rows: ' + table.getNumRows());
  }
  </code></pre>
  
  <p>The output is: </p>
  
  <pre><code>[14-11-25 15:02:26:275 CET] num rows: 1077
  [14-11-25 15:02:26:353 CET] num rows: 1117
  </code></pre>
  
  <p>But I don't see the newly created rows in the document.
  If I manually insert a row form the UI, and then re-execute the script I get: </p>
  
  <pre><code>[14-11-25 15:04:24:317 CET] num rows: 1118
  [14-11-25 15:04:24:400 CET] num rows: 1158
  </code></pre>
  
  <p>So it seems that the code is actually working on the right table, but I don't see the new rows in the document itself. </p>
  
  <p>The log says 1158 rows but the document actually just has ~30 rows</p>