I've taken the code below from Write data to Google Sheet using Google Sheet API V4 - Java Sample Code @"Ashwin Karangutkar". Which writes to cells in the googlespread sheets.
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?
Thank you in advance.
Kind regards,
Nikos.
Aswin's code example
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<List<Object>> arrData = getData();
ValueRange oRange = new ValueRange();
oRange.setRange(range); // I NEED THE NUMBER OF THE LAST ROW
oRange.setValues(arrData);
List<ValueRange> oList = new ArrayList<>();
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<List<Object>> getData () {
// Add data to horizontal axis (same row)
List<Object> data1 = new ArrayList<Object>();
data1.add ("Example");
data1.add ("Example2");
System.out.println("Values");
// add data to vertical axis (new row)
List<List<Object>> data = new ArrayList<List<Object>>();
data.add (data1);
return data;
}