2017-06-18 54 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

相關問題