At Google I/O 2016, we launched a new Google Sheets API—click hereto watch the entire announcement. The updated API includes many new features that weren’t available in previous versions, including access to functionality found in the Sheets desktop and mobile user interfaces. My latest DevBytevideo shows developers how to get data into and out of a Google Sheet programmatically, walking through a simple script that reads rows out of a relational database and transferring the data to a brand new Google Sheet.
Let’s take a sneak peek of the code covered in the video. Assuming that
SHEETS has been established as the API service endpoint,
SHEET_ID is the ID of the Sheet to write to, and
datais an array with all the database rows, this is the only call developers need to make to write that raw data into the Sheet:
SHEETS.spreadsheets().values().update(spreadsheetId=SHEET_ID,Reading rows out of a Sheet is even easier. With
range='A1', body=data, valueInputOption='RAW').execute()
SHEET_IDagain, this is all you need to read and display those rows:
rows = SHEETS.spreadsheets().values().get(spreadsheetId=SHEET_ID,
for row in rows:
We hope all these resources help developers create amazing applications and awesome tools with the new Google Sheets API! Please subscribe to our channel, give us your feedback below, and tell us what topics you would like to see in future episodes!