gspread或这样的:帮助我获取单元格坐标(不是值) [英] gspread or such: help me get cell coordinates (not value)

查看:463
本文介绍了gspread或这样的:帮助我获取单元格坐标(不是值)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆