This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sheet_title = "Sheet1" | |
full_data = [["first_name", "last_name"], ["Segun", "Oba"], ["Lafongido", "Moses"], ["Abraham", "Sanni"]] | |
spreadsheet.values_update( | |
sheet_title+'!A1', | |
params={'valueInputOption': 'RAW'}, | |
body={'values': full_data} | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
worksheet.update('A1', [columns, *rows], value_input_option="USER_ENTERED") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
columns = ["first_name", "last_name" ] | |
rows = [["Segun", "Chukwudi"], ["Sola", "Ahmed"], ["Ibukun", "Emeka"]] | |
worksheet.update('A1', [columns, *rows]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Update a range of cells using the top left corner address | |
worksheet.update('A1', [["first_name", "last_name" ], ["Segun", "Chukwudi"]]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
worksheet.update('B2', "Hi, I'm the new cell value") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# get values as list of key pair values | |
all_values = worksheet.get_all_records(value_render_option="FORMULA") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# get values in the first row | |
values_list = worksheet.row_values(1) | |
# get values in the first column | |
values_list = worksheet.col_values(1) | |
# get values as 2D list | |
all_values = worksheet.get_all_values() | |
# get values as list of key pair values |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create Worksheet | |
worksheet = spreadsheet.add_worksheet(title="New worksheet", rows=100, cols=20) | |
# Delete Worksheet | |
spreadsheet.del_worksheet(worksheet) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# get worksheet by index | |
worksheet = sh.get_worksheet(0) | |
# get worksheet by title | |
worksheet = sh.worksheet("tab title") | |
# get sheet by sheet1 | |
worksheet = sh.sheet1 | |
# get all worksheets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gspread | |
gc = gspread.service_account("path/to/service_account.json") | |
# Open Spreadsheet by name | |
spreadsheet = gc.open("My Spreadsheet Title") | |
# Open Spreadsheet by url | |
spreadsheet = gc.open_by_url("https://docs.google.com/spreadsheet/theSheetId") |