title: Google Spread sheets, appending data using /java
body: <p>I've taken the code below from <a href="https://stackoverflow.com/questions/38107237/write-data-to-google-sheet-using-google-sheet-api-v4-java-sample-code">Write data to Google Sheet using Google Sheet API V4 - Java Sample Code</a> @"Ashwin Karangutkar". Which writes to cells in the googlespread sheets.</p>
  
  <p>But I really want to do, is to get this data appended to the sheets instead or writing on the first row. I've come across AppendCellsRequest function of the api, but I'm not too sure how to integrate it. Can anyone help me with this?</p>
  
  <p>Thank you in advance.</p>
  
  <p>Kind regards,</p>
  
  <p>Nikos.</p>
  
  <p><strong>Aswin's code example</strong></p>
  
  <pre><code> public static void setValue(String SheetName,String RowStart, String RowEnd) throws IOException{
      // Build a new authorized API client service.
      Sheets service = getSheetsService();
      // Prints the names and majors of students in a sample spreadsheet:
      String spreadsheetId = "17PQyEPayrHSIgvPtrfZtItuUcArhvjDy-G68Xg02s3s";
      String range = SheetName+"!"+RowStart+":"+RowEnd;
      Integer sheetLocationNumber = 0;
  
  
      List&lt;List&lt;Object&gt;&gt; arrData = getData();
  
      ValueRange oRange = new ValueRange();
      oRange.setRange(range); // I NEED THE NUMBER OF THE LAST ROW
      oRange.setValues(arrData);
  
      List&lt;ValueRange&gt; oList = new ArrayList&lt;&gt;();
      oList.add(oRange);
  
      BatchUpdateValuesRequest oRequest = new BatchUpdateValuesRequest();
      oRequest.setValueInputOption("RAW");
      oRequest.setData(oList);
  
      BatchUpdateValuesResponse oResp1 = service.spreadsheets().values().batchUpdate(spreadsheetId, oRequest).execute();
  
      // service.spreadsheets().values().update (spreadsheetId, range,) ;
      //return request;
  }
  
  public static List&lt;List&lt;Object&gt;&gt; getData ()  {
  </code></pre>
  
  <p>// Add data to horizontal axis (same row)</p>
  
  <pre><code>    List&lt;Object&gt; data1 = new ArrayList&lt;Object&gt;();
      data1.add ("Example");
      data1.add ("Example2");
      System.out.println("Values");
  </code></pre>
  
  <p>// add data to vertical axis (new row)</p>
  
  <pre><code>    List&lt;List&lt;Object&gt;&gt; data = new ArrayList&lt;List&lt;Object&gt;&gt;();
      data.add (data1);
  
      return data;
  }
  </code></pre>