python - 如何使用 gspread 获取 Google 电子表格单元格链接

标签 python google-sheets google-account gspread

只有一个 Google 电子表格文档。 从右键单击下拉菜单中选择第一个 A1 单元格后,我选择:Get Link to this Cell 命令。

URL 链接现在存储在内存中,可以粘贴到任何文本编辑器中。复制的单元格的 URL 链接如下所示:

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

问题:如何在 Python 中使用 gspread 获取同一个单元格的链接?

最佳答案

首先,您需要生成 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')

然后就可以抓取你想要的cell了

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

所有代码都是从 gspread Github 的基本用法中提取的,稍作调整 https://github.com/burnash/gspread

干杯!

关于python - 如何使用 gspread 获取 Google 电子表格单元格链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44610712/

相关文章:

python - 尝试使用 Vyatta 的非标准命令时出现 Paramiko "Invalid command"

javascript - 查看命名范围并将值打印到新工作表

date - 查询和今日功能

javascript - 我无法获取从单元格 b2 输入的值

git - Bitbucket git 凭据(如果已与 Google 签约)

android - 在没有客户经理的情况下在android中使用谷歌客户端API

python - Openpyxl load_workbook 和保存时间太长

python - 如何不反转十进制数?

python - 函数输出不显示任何内容,Python

android - 通过 Android(pre-2.0)访问 Google 帐户 ID/用户名