【发布时间】:2019-07-31 23:36:51
【问题描述】:
我正在尝试使用 Google Drive/Sheets API 从 Google Drive 读取工作表。我想知道如何在不同的标签之间导航。
(忽略其他的东西,这是一张展示标签是什么的随机图片。)
基本上,我想要做的是能够访问其他选项卡并阅读那里的文本。每个选项卡的格式相同。我已经能够从第一个选项卡中读取内容,并且也希望对其他选项卡执行相同的操作。
这是我的代码:
import gspread
from oauth2client.service_account import ServiceAccountCredentials
import pprint
# Use credentials to interact with the Google Drive API
scope = ['https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive']
credentials = ServiceAccountCredentials.from_json_keyfile_name(
'foo', scope)
client = gspread.authorize(credentials)
# Opening the first sheet
sheet = client.open("Resume Data").sheet1
# Prints the code in a nicer format
pp = pprint.PrettyPrinter()
# Extract and print all of the values
list_of_resumes = sheet.get_all_records()
# Printing
pp.pprint(list_of_resumes)
【问题讨论】:
-
关于
I've been able to read from the first tab,你能提供你的脚本吗?如果可以,请将其添加到您的问题中。通过这种方式,我们可以了解您访问电子表格的方法。当然,请删除您的个人信息。 -
@Tanaike 我现在已经做到了。谢谢!
-
感谢您的回复和补充信息。我提出了一个修改后的脚本作为答案。你能确认一下吗?如果我误解了您的问题并且这不是您想要的结果,我深表歉意。
标签: python google-drive-api google-sheets-api