I have the following code using the Google sheets API and got it working perfectly. It sees all my data and puts it into the app perfectly via the for
loop. It runs through the spreadsheets and puts the data in an edit view.
private List<String> getDataFromApi() throws IOException {
String spreadsheetId = "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms";
String range = "Class Data!A2:E";
List<String> results = new ArrayList<String>();
ValueRange response = this.mService.spreadsheets().values()
.get(spreadsheetId, range)
.execute();
List<List<Object>> values = response.getValues();
if (values != null) {
results.add("Name, Major");
for (List row : values) {
results.add(row.get(0) + ", " + row.get(4));
}
}
return results;
}
As you can see, the for
loop retrieves the data one by one until there is no more data inside a specific range in the spreadsheet.
My question: I want to retrieve a specific range, not using a for
loop. However, as an example, if I want to get cell A1, and I do result.add(A.get(0))
, it doesn't work.
How can I retrieve a specific range within the spreadsheet.