Skip to content

Instantly share code, notes, and snippets.

Last active January 17, 2021 07:35
What would you like to do?
A small snippet of code to exhibit the functionality of Google Sheets in Python.
import gspread
from oauth2client.service_account import ServiceAccountCredentials
from pprint import pprint
#sheet access
scope = ["",'',"",""]
# used to retrieve credentials from the *creds.json* file
creds = ServiceAccountCredentials.from_json_keyfile_name("creds.json", scope)
client = gspread.authorize(creds)
# We're accessing the sheet 1 of the tester document
sheet ="tester").sheet1
# retrieves all records
print("\nRetrieving all records...")
data = sheet.get_all_records()
# retrieving specific row values
print("\nRetrieving information from row 3...")
row = sheet.row_values(3)
# retrieving specific column values
print("\nRetrieving information from column 3...")
col = sheet.col_values(3)
# retrieving specific cell
print("\nRetrieving value of a cell placed at (1, 2) in the sheet...")
cell = sheet.cell(1, 2).value
# inserting details into the sheet
print("\nInserting details into the sheet...")
insertDetails = ["Adithya", "", "33YEP4554"]
sheet.insert_row(insertDetails, 1)
# updating details in the sheet
print("\nUpdating details in the sheet...")
sheet.update_cell(2, 2, "")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment