Created
April 14, 2017 17:05
-
-
Save zevaverbach/71eed69c399432ba22ed673bbdd81b82 to your computer and use it in GitHub Desktop.
Get the value of the first cell of a named range from Google Sheets.
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 pygsheets | |
def get_value_of_named_range_from_google_sheet(sheet_name: str, worksheet_title: str, range_name: str) -> str: | |
"""return the value of the first cell from a named range | |
great for treating Google Sheets NamedRanges as variables in Python scripts""" | |
# https://pygsheets.readthedocs.io/en/latest/authorizing.html | |
gc = pygsheets.authorize(outh_file='client_secret.json', outh_nonlocal=True) | |
sh = gc.open(sheet_name) | |
wks = sh.worksheet_by_title(worksheet_title) | |
named_range = wks.get_named_ranges(range_name) | |
if named_range: | |
return named_range[0][0].value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment