Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update/write data to google spreadsheet api android (api v4)

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

like image 532
Shekhar Avatar asked Jun 27 '16 11:06

Shekhar


People also ask

How do I update data in Google spreadsheet?

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.


1 Answers

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.

like image 133
Veiga Avatar answered Oct 01 '22 13:10

Veiga