gspread或这样的:帮助我获取单元格坐标(不是值) [英] gspread or such: help me get cell coordinates (not value)
问题描述
通过使用GSpread,我有一系列从谷歌电子表格返回的单元格,其所有元素如下所示:
< Cell R1C1'Sandero'>
我知道如何从这里获得单元格值:
cell.value
但我也会喜欢分别获取地址(本例中为R1C1)。
如果我可以使用(1,1)格式(可能通过使用字典),它必须是(R1,C1),甚至更好?
<你看我也需要这个地址,因为我稍后会用这些值声明一个图。
我使用Python 2.7和最新的Gspread库。
>任何帮助都将受到高度赞赏。
获取单元格坐标的最佳方法是使用单元格的实例属性 row
和 col
。这样你的代码可以简化为:
为cell_list中的单元格:
print cell.value
打印Row:,cell.row,Column:,cell.col
一个元组,将它包装在括号中:(cell.row,cell.col)
。
我是gspread的作者,我已经更新了库页面它清楚如何获得细胞的坐标。感谢您指出缺少的部分。
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.
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.
这篇关于gspread或这样的:帮助我获取单元格坐标(不是值)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!