2017-06-18 139 views
0

有一个Google电子表格文档。 从右键单击下拉菜单中选择第一个A1单元格后,我选择:Get Link to this Cell命令。如何使用gspread获取Google Spreadsheet单元格链接

URL链接现在存储在内存中,可以粘贴到任何文本编辑器中。复制的单元格的URL链接应该是这样的:

https://docs.google.com/spreadsheets/d/f8s9HO0sidw9qIGwuqYq1wFFb9QWWpuFIXE3flYcgBG1/edit?ts=7559594f#gid=2879414198&range=A1

问:如何开始使用Python中gspread在同一小区的链接?

回答

-1

首先,您需要产生的OAuth2凭证: http://gspread.readthedocs.io/en/latest/oauth2.html

你需要使用的OAuth2凭据在你的Python创建一个新的授权对象:

gc = gspread.authorize(credentials) 

然后,你需要创建到工作表的连接:

# If you want to be specific, use a key (which can be extracted from 
# the spreadsheet's url) 
yoursheet = gc.open_by_key('0BmgG6nO_6dprdS1MN3d3MkdPa142WFRrdnRRUWl1UFE') 

# Or, if you feel really lazy to extract that key, paste the entire url 
yoursheet = gc.open_by_url('https://docs.google.com/spreadsheet/ccc?key=0Bm...FE&hl') 

然后您可以抓取细胞你想

val = yoursheet.acell('B1').value 

所有的代码是从gspread Github上基本用法与拉小的调整https://github.com/burnash/gspread

干杯!

+0

'val = yoursheet.acell('B1').value'命令返回单元格填充(填充)的值。但我的问题是如何获取单元格的URL--当您右键单击并运行“获取链接到此单元格”命令时获得的URL链接。 – alphanumeric

+0

嗯...我不认为Google通过Sheets API公开了该功能。我想有几种复制打开页面和提取价值的方法,但我不知道是否有任何简单的方法来做到这一点。 – zachMade

相关问题