![](/img/trans.png)
[英]Get link inside href tag from cell in Google Spreadsheet (gspread)
[英]How to get Google Spreadsheet cell link with gspread
只有一個Google電子表格文檔。 從右鍵單擊下拉菜單中選擇第一個A1
單元后,我選擇: Get Link to this Cell
命令。
URL鏈接現在存儲在內存中,並且可以粘貼到任何文本編輯器中。 復制的單元格的URL鏈接如下所示:
問題:如何在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')
然后,您可以抓住想要的單元
val = yoursheet.acell('B1').value
所有代碼均通過細微調整從gspread Github基本用法中提取出來https://github.com/burnash/gspread
干杯!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.