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.
You can get the column value by using Cell.col
.
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