gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 07:44:53 24 4
gpt4 key购买 nike

我只想通过我的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com