Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding cell using Pygsheets and update cells in the same column

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.

like image 643
MariaMH Avatar asked Feb 10 '26 04:02

MariaMH


1 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:

  • Cell - pygsheets 1.1 documentation
    • col - Cell - pygsheets 1.1 documentation
like image 98
I hope this is helpful to you Avatar answered Feb 16 '26 08:02

I hope this is helpful to you



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!