0
# 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'>

itChi
  • 642
  • 6
  • 19

1 Answers1

1

Here's the pygsheets documentation: https://pygsheets.readthedocs.io/en/stable/index.html

And the relevant sections:


Looks 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)
blueteeth
  • 3,330
  • 1
  • 13
  • 23
  • Thanks, point taken about making this a list instead. I do need to access both the range and the value. Is there any way to do something like `my_list[6].range`? – itChi Jan 27 '20 at 16:59
  • your solution returned `AttributeError: 'list' object has no attribute 'value'` – itChi Jan 27 '20 at 17:05
  • Hmm, looks like you're actually getting a list of lists. I'll edit my answer – blueteeth Jan 27 '20 at 17:14
  • I appreciate that this is a separate question, but what I'd actually like to do, is select cell by contents, and apply formatting (change cell background). But I get the same type of data returned when I use the find operator. – itChi Jan 28 '20 at 10:23