3

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.

MariaMH
  • 55
  • 1
  • 2
  • 5

2 Answers2

1

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:

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Rafa Guillermo
  • 14,474
  • 3
  • 18
  • 54
0

use my_cell[0].address.label

this will yield 'H2' in your case

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 30 '22 at 08:18