Finding cell using Pygsheets and update cells in the same column

Question:

I need to update every week a calendar in a Google Sheet with some numbers.
I’m using pygsheets find to find the date, but them I am unable to get the column of that cell so I can update some rows within that column.

enter code here
for key in list:
    sheet_name = list[key]
    print(sheet_name)
    # Access the sheet
    sheet = report.worksheet_by_title(sheet_name)
    header = sheet.find(first_day_period)
    print(header)
[<Cell H2 '21 Sep 2020'>]

What find returns is a list of cells, but I can’t access the column without splitting the result and then use that to find the cell. I was wondering if there was an easier, cleaner way of doing it.

Asked By: MariaMH

||

Answers:

Answer:

You can get the column value by using Cell.col.

More Information & Example:

As per the pygsheets documentation on the Cell class, there is a col value:

col

Column number of the cell.

import pygsheets

gc = pygsheets.authorize()
ss = gc.open_by_key('sheet-id')
sheet = ss.worksheet_by_title(sheet_name)
header = sheet.find(first_day_period)

print(header[0].col)

Under the assumption that the value contained within first_day_period is in cell I1, the console output will be:

9

References:

use
my_cell[0].address.label

this will yield ‘H2’ in your case

Answered By: Jan Spieckermann
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.