python - 通过 Google Sheets API 和 Python 阅读 Sheet 2

标签 python google-api

我只想通过我的 Google Sheets 项目中的 API 使用 Python (Windows 10) 读取下一个选项卡/工作表 一切都适用于工作表 1,我只想阅读/编辑工作表 2(以及我将在项目中创建的其他工作表) .

选项卡示例:/image/d4Ee9.jpg

import gspread
from oauth2client.service_account import ServiceAccountCredentials
scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
creds = ServiceAccountCredentials.from_json_keyfile_name('client_penny.json', scope)
client = gspread.authorize(creds)

penny = client.open('pennystocks').sheet1

print(penny.get_all_records())

这有效:penny = client.open('pennystocks').sheet1

这不是:penny = client.open('pennystocks').sheet2

最佳答案

  • 您想要使用 gspread 来使用除第一个选项卡的工作表之外的工作表。
    • 例如,当电子表格中有 2 张“Sheet1”和“Sheet2”时,您希望使用“Sheet2”。

如果我的理解是正确的,那么修改一下怎么样?

来自:

penny = client.open('pennystocks').sheet1

致:

penny = client.open('pennystocks').worksheet('Sheet2')

注意:

  • client.open('pennystocks').sheet1 打开工作表的第一个索引。例如,在电子表格中,当“Sheet1”的索引修改为“Sheet2”时,client.open('pennystocks').sheet1 返回“Sheet2”。

引用:

如果我误解了您的问题并且这不是您想要的结果,我深表歉意。

关于python - 通过 Google Sheets API 和 Python 阅读 Sheet 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56510027/

相关文章:

python - 通过 View 动态改变django的DEBUG模式

python - 绘制直方图 : TypeError: cannot perform reduce with flexible type

android - 谷歌图书 API

google-app-engine - Google Calendar api - 超出速率限制(即使不是)

youtube - YouTube Content ID API突然为所有内容提供403

python - Pyqt5 qthread + 信号不工作 + gui 卡住

python - "else"在 Python 中被认为是有害的?

android - 我们可以在离线模式下使用 Google 的 Fused Location 服务吗?

python - Google Python API 客户端使用refresh_token刷新access_token

python - 在Python中通过拆分另一个列表的索引来创建列表可能吗?