Upload
wesley-chun
View
171
Download
1
Embed Size (px)
Citation preview
The power & flexibilityof the new Google Sheets API
+Wesley ChunDeveloper Advocate, G Suite
Sundar SolaiDeveloper Programs Engineer, G Suite
Contribute questions at:
goo.gl/Rq6ABI
Outline● Introducing Sheets API v4● Primary use case categories● Specific API usage examples
○ Bulk loading values (SQL database migration)○ Formatting spreadsheet cells○ Generating presentations from spreadsheet
data○ Big data & analytics case study
● Summary● Live demos (time-permitting)
Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem
Proprietary + Confidential
Introducing Sheets API v4
• Create new sheets within spreadsheets• Add data to sheets• Read data from sheets
?Sheets API v4 launch announcementgoo.gl/ikttYs
• Create new sheets within spreadsheets• Add data to sheets• Read data from sheets
• Create new spreadsheets• Set frozen rows• Add cell formatting• Adjust column sizes• Apply formulas• Build pivot tables • Create charts• … and more!
• Create new sheets within spreadsheets• Add data to sheets• Read data from sheets
Sheets API endpoints● spreadsheets
○ batchUpdate○ create○ get
● spreadsheets.sheets○ copyTo
● spreadsheets.values○ append○ batchClear○ batchGet○ batchUpdate○ clear○ get○ update
Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem
Proprietary + Confidential
Primary use case categories
Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem
Proprietary + Confidential
Bulk loading values(SQL database migration)
SQL database migration
Code sample video + blog postgoo.gl/N1RPwC
Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem
Proprietary + Confidential
Formatting spreadsheet cells
• Frozen rows• Font/face formatting• Data type formatting• Data validation
Cell formatting
Batch API request structure
• Frozen rows• Font/face formatting• Data type formatting• Data validation
0 1 5
0
5
column index
● Range made up of Sheet ID & indexes● First auto-created Sheet: default ID 0● Index count starts at zero● Exclusive of end{Row,Column}Index● May omit an index dep. on scenario
rowindex
. . . . . .
Cell ranges
column index
● Range made up of Sheet ID & indexes● First auto-created Sheet: default ID 0● Index count starts at zero● Exclusive of end{Row,Column}Index● May omit an index dep. on scenario
rowindex
"range": { "sheetId": ?, "startColumnIndex": ?, "endColumnIndex": ?, "startRowIndex": ?, "endRowIndex": ?, },
.
.
. . . . . .0 1 5
0
5
Quiz!
column index
● Range made up of Sheet ID & indexes● First auto-created Sheet: default ID 0● Index count starts at zero● Exclusive of end{Row,Column}Index● May omit an index dep. on scenario
rowindex
.
.
. . . . . .0 1 5
0
5
GridRange documentationsearch @ developers.google.com/sheets
"range": { "sheetId": 0, "startColumnIndex": 3, "endColumnIndex": 5, "startRowIndex": 2, "endRowIndex": 4, },
GridRange
• Frozen rows• Font/face formatting• Data type formatting• Data validation
• Frozen rows• Font/face formatting• Data type formatting• Data validation
Cell & range formattingdevelopers.google.com/sheets/api/samples/formatting
Update fieldmasks docs & video+postdevelopers.google.com/sheets/guides/batchupdate#field_masksgoo.gl/Zhep1i
Frozen and bold rows
Currency formatting (JSON)
• Frozen rows• Font/face formatting• Data type formatting• Data validation
Sheets date, time, and number formatsdevelopers.google.com/sheets/api/guides/formats
Cell validation (JSON)
• Frozen rows• Font/face formatting• Data type formatting• Data validationCode sample video + blog post
goo.gl/U6Oljn
Cell formatting code challenge!
Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem
Proprietary + Confidential
Generating presentationsfrom spreadsheet data
Code sample video + blog postgoo.gl/Yb06ZC
Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem
Proprietary + Confidential
Big data & analytics case study
Public Datasets
● Major League Baseball 2016● Chicago Taxi Trips● GitHub Data● Hacker News● Medicare Data● San Francisco Police Reports● World Bank: Education Statistics● And more!
service.spreadsheets().create(body=spreadsheet_body).execute()
Design your spreadsheet on creation
What’s in a Sheet object?
Sheet 0: Game Log
"properties": { "sheetId": 0, "title": “Game Log”, "gridProperties”: {
“frozenRowCount”: 1}
}
"data": [{
"startRow": 0,“startColumn”: 0,“rowData”: [
{“values”: [
{“userEnteredvalue”: {
“stringValue”: columnName}
} for columnName in columnNames]
}]
}]
"conditionalFormats": [ {
“ranges”: [{
“sheetId”: 0,“startRowIndex”: 1,“startColumnIndex”: 6,“endColumnIndex”: 7
}],“booleanRule”: {
“condition”: {“type”: “NUMBER_LESS”,“values”: [
{“userEnteredValue”: “= H2”
}]
}},“format”: {
“backgroundColor”: {“red”: 1,“green”: 0,“blue”: 0
}}
},...
]
List comprehensions to the rescue (again)! "conditionalFormats": [ {
“ranges”: [{
“sheetId”: 1,“startRowIndex”: 1,“startColumnIndex”: x,“endColumnIndex”: x + 1
}],“gradientRule”: {
“minpoint”: {“color”: {
“red”: 1,“green”: 0,“blue”: 0
},“type”: “MIN”
},“midpoint”: {...},“maxpoint”: {...}
}} for x in range(4, 12)
]
Sheet 2: Pitching
Filter View
Sheet 2: Pitching "filterViews": [ {
“filterViewId”: 0,“title”: “Batters Faced”,“range”: {
“sheetId”: 2,“endRowIndex”: numberPitchers + 1,“endColumnIndex”: 21
},“sortSpecs”: [
{“dimensionIndex”: 4,“sortOrder”: “DESCENDING”
}]
},...
]
Pivot tables"pivotTable”: {
“source:” {“sheetId”: 0,“endColumnIndex”: 12
},“rows”: [
{“sourceColumnOffset”: 5,“showTotals”: True,“sortOrder”: “ASCENDING”
}],“columns”: [...],“values”: [
{“summarizeFunction”: “AVERAGE”,“sourceColumnOffset”: 6
},...
]}
Charts
Query function brings SQL to Sheets= Sum(Query('Pitch Log'!A:EO, "SELECT COUNT(BC) WHERE BJ = 0 AND BK = 0",1))
Guest appearance: Drive APIfile_metadata = {
“name”: “Baseball Sheets”,“Mimetype”: “application/vnd.google-apps.folder”
}
folder = service.files().create(body=file_metadata, fields=”id”).execute()
………
file = service.files().get(fileId=response['spreadsheetId'],fields='parents').execute()
prev_parents = ', '.join(file.get('parents'))service.files().update(fileId=response['spreadsheetId'],
addParents=folder.get('id'),removeParents=prev_parents,fields='id, parents').execute()
Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem
Proprietary + Confidential
Summary
DATABASE
ANALYZERVISUALIZER
ORGANIZER
• Business-critical tool• Even with big data• Flexible by nature• New Sheets API v4○ More power than
predecessors• Not your only tool• Power your apps!
Thank you! Q&A
+Wesley Chungoogle.com/+WesleyChun
@wescpytwitter.com/wescpy
Sundar Solailinkedin.com/in/sundar-solai
slide deckgoo.gl/Nnd5ry
Contribute questions at:
goo.gl/Rq6ABI