I have been working on an application where I need to write and update data to a spreadsheet using google spreadsheet api. I have followed the Android Quickstart provided by google Google Sheets API Android Quickstart and was able to retreive data from the google spreadsheet but I am not able to understand how to write data. Please help
Visit Google Sheets and open the spreadsheet where you want to locate and update your data. Click Edit > Find and Replace from the menu. When the Find and Replace window displays, enter the data you want to locate in the Find box. Then, in the Replace With box, enter what you want to update it with.
If you followed the Quickstart tutorial correctly, then it you are few steps from learning how to write data.
In the code provided in the Quickstart tutorial, change the line
private static final String[] SCOPES = { SheetsScopes.SPREADSHEETS_READONLY };
to:
private static final String[] SCOPES = { SheetsScopes.SPREADSHEETS };
This will grant access to write on a spreadsheet.
And instead of something like
ValueRange response = this.mService.spreadsheets().values()
.get(spreadsheetId, range)
.execute();
List<List<Object>> values = response.getValues();
you must create your own ValueRange instance, valueRange in this example, and then write:
this.mService.spreadsheets().values().update(spreadsheetId, range, valueRange)
.setValueInputOption("RAW")
.execute();
Choose the ValueInputOption of your preference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With