Wednesday, September 9, 2020

Google Spread Sheets with Python

# https://www.youtube.com/watch?v=4at0BuA6Zck&t=479s

# https://www.youtube.com/watch?v=T1vqS1NL89E&feature=emb_rel_pause

# https://gspread.readthedocs.io/en/latest/user-guide.html#deleting-a-worksheet


import gspread

from oauth2client.service_account import ServiceAccountCredentials


scope = ["https://www.googleapis.com/auth/drive"]

credentials = ServiceAccountCredentials.from_json_keyfile_name('Creds.json', scope)

client = gspread.authorize(credentials)

sheet = client.open("Test").sheet1


data = sheet.get_all_records();  print(data)

data = sheet.get_all_values();   print(data[1:])

data = sheet.row_values(2);      print(data)

data = sheet.get('B2');          print(data)

data = sheet.get('A2:B3');       print(data)


sheet.append_row(["Susan", "971506323527"])

sheet.insert_row(["Thejus", "8075849686"], 5)  # Inserts in 5th row

data = sheet.get_all_values();   print(data[1:])


sheet.update_cell(5, 1, "Kuttappan")         # Modify Row 5 Column 1

data = sheet.get_all_values();   print(data[1:])


sheet.delete_rows(5)

sheet.delete_rows(5)

sheet.append_row(["Thejus", 8075849686])

sheet.insert_row(["Susan",  971506323527], 6)

data = sheet.get_all_values();   print(data[1:])

No comments:

Post a Comment