Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gspread or such: help me get cell coordinates (not value)

By using GSpread I have a range of cell's returned from a google spreadsheet that has all its elements something like this:

<Cell R1C1 'Sandero'>

I know how to get from here the cell value:

cell.value

but I would also like to get the address (R1C1 in this case) separately. It would have to be (R1,C1) or even better if I can get it in (1,1) format (maybe by using a dictionary?)

You see I need the address as well because I will later declare a graph with these values.

I'm using Python 2.7 and latest Gspread library.

Any help would be greately appreciated.

like image 616
Laci Avatar asked Dec 19 '12 09:12

Laci


1 Answers

The best way to get a cell's coordinates is by using the cell's instance properties row and col. This way your code can be simplified to this:

for cell in cell_list:
    print cell.value
    print "Row:", cell.row, "Column:", cell.col

To get a tuple, just wrap it in parenthesis: (cell.row, cell.col).

Since I'm the author of gspread, I've updated the library page to make it clear how to get a cell's coords. Thanks for pointing out the missing part.

like image 112
Burnash Avatar answered Oct 10 '22 02:10

Burnash