title: Import google calendar data into existing google spreadsheet
body: <p>I am trying to keep a record of google calendar entries in a google spreadsheet to further process the data. I have the following code, which I borrowed from other sources:</p>
  
  <pre class="lang-js prettyprint-override"><code>function importEvents(){
    var startOfDay = new Date();
        startOfDay.setUTCHours(0);
        startOfDay.setMinutes(0);
        startOfDay.setSeconds(0);
        startOfDay.setMilliseconds(0);  
    var endOfDay = new Date(startOfDay.getTime() + 24 * 60 * 60 * 1000);
  
    var Calendar = CalendarApp.getCalendarById("[calendarIDhere]");
    var events = Calendar.getEvents(startOfDay, endOfDay)
    var events_sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("ImportedEvents");
    var lr = events_sheet.getLastRow();
  
    var eventarray = new Array();
  
    var i = 0; // edited
      for (i = 0; i &lt; events.length; i++) {
        line = new Array();
        line.push(events[i].getTitle());
        line.push(events[i].getDescription());
        line.push(events[i].getStartTime());
        line.push(events[i].getEndTime());
        eventarray.push(line);
      }
  
      events_sheet.getRange('A1:D' + (i)).setValues(eventarray);
  
    var l = events_sheet.getLastRow();
    var m = events_sheet.getMaxRows();
    events_sheet.deleteRows(l+1,m-l);
  }
  </code></pre>
  
  <p>For some reason, every time I import a day's entries, several empty rows are added to the ImportedEvents sheet. This is why I delete the empty rows at the end of the sheet.</p>
  
  <p>What I would like to do is to have this script append new imported entries below existing entries in the ImportedEvents sheet. I can't figure this out because of my limited programming skills (again, the code above is the result of implementing solutions provided elsewhere).</p>
  
  <p>Any help will be greatly appreciated!</p>
  
  <p><strong>EDIT:</strong> Based on Lothar's suggestion, I tried something else:</p>
  
  <pre class="lang-js prettyprint-override"><code>events_sheet.getRange("A"+(lr+1)+":D"+(lr+i)).setValues(eventarray);
  </code></pre>
  
  <p>And it worked! Also, a very special thank you to whomever voted -1 for the incentive to dig deeper. </p>
  
  <p>Cheers!</p>