# Authorize Spreadsheet Access
gc = pygsheets.authorize(service_file=gServiceAccAuthFile, retries=1)
# Open spreadsheet
sh = gc.open_by_key(gSheetKey)
# Open Worksheet
wks = sh.worksheet_by_title(gWorksheetName)
mydict = wks.get_values('A1','A55',returnas='cell')
print(mydict[5])
[<Cell A6 'MY CELL CONTENTS'>]
I'd like to find out what this data type is, and how I can use the separate values (Cell A6
(or just A6
) and MY CELL CONTENTS
).
I've tried print(mydict[5][0])
but this just returns:
<Cell A6 'MY CELL CONTENTS'>
Here's the pygsheets
documentation: https://pygsheets.readthedocs.io/en/stable/index.html
And the relevant sections:
Worksheet.get_values()
: https://pygsheets.readthedocs.io/en/stable/worksheet.html#pygsheets.Worksheet.get_valuesCell
: https://pygsheets.readthedocs.io/en/stable/cell.html#pygsheets.Cell.valueLooks like your selection gets a list of lists of Cell
objects, so it would make more sense to call it my_list
.
You can access the value with Cell.value
. In this case my_list[6][0].value
.
If you want to specifically access the value of A6, there's no need to select the entire range. You can use Worksheet.get_value
.
print(wks.get_value('A6'))
Or if you do actually need the cell,
a6 = wks.cell('A6')
print(a6.value)