模块' gspread.worksheet'没有属性' update_cell'

发布于 2025-02-02 20:33:48 字数 837 浏览 2 评论 0原文

我的代码:

import gspread
from gspread import worksheet
from oauth2client.service_account import ServiceAccountCredentials
scope = ["https://spreadsheets.google.com/feeds",'https://www.googleapis.com/auth/spreadsheets',"https://www.googleapis.com/auth/drive.file","https://www.googleapis.com/auth/drive"]
creds = ServiceAccountCredentials.from_json_keyfile_name("keys.json", scope)
client = gspread.authorize(creds)
spreadsheet = client.open("ackerwaldundwiese")
worksheet.update_cell(1, 2, "car")

输出

Traceback (most recent call last):
  File "C:\Users\mm\PycharmProjects\pythonProject1\ddf.py", line 8, in <module>
    worksheet.update_cell(1, 2, "car")
AttributeError: module 'gspread.worksheet' has no attribute 'update_cell'

我正在使用Pycharm 2022.1.1(社区版)Windows 10

My code:

import gspread
from gspread import worksheet
from oauth2client.service_account import ServiceAccountCredentials
scope = ["https://spreadsheets.google.com/feeds",'https://www.googleapis.com/auth/spreadsheets',"https://www.googleapis.com/auth/drive.file","https://www.googleapis.com/auth/drive"]
creds = ServiceAccountCredentials.from_json_keyfile_name("keys.json", scope)
client = gspread.authorize(creds)
spreadsheet = client.open("ackerwaldundwiese")
worksheet.update_cell(1, 2, "car")

Output

Traceback (most recent call last):
  File "C:\Users\mm\PycharmProjects\pythonProject1\ddf.py", line 8, in <module>
    worksheet.update_cell(1, 2, "car")
AttributeError: module 'gspread.worksheet' has no attribute 'update_cell'

I'm using PyCharm 2022.1.1 (Community Edition) windows 10

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

究竟谁懂我的在乎 2025-02-09 20:33:48

嗨,在访问工作表之前,您必须先检索它。

在您的情况下,应该像以下方式一样:

spreadsheet = client.open("ackerwaldundwiese")
worksheet = spreadsheet.sheet1
worksheet.update_cell(1, 2, "car")

注意:如果您需要获得不同的表,则将返回第一张纸,使用方法 get_worksheet

从代码中删除此行

from gspread import worksheet

您应该 这很敏感,因此 w orksheet对象不存在,但 w orksheet确实存在。

Hi before accessing a worksheet you must retrieve it first.

In you situation it should be sometlike this:

spreadsheet = client.open("ackerwaldundwiese")
worksheet = spreadsheet.sheet1
worksheet.update_cell(1, 2, "car")

Note: this will return the first sheet, if you need to get a different sheet use the method get_worksheet

You should remove this line from your code:

from gspread import worksheet

You don't need to import the Worksheet object and it is case sensitive so the worksheet object does not exists but the Worksheet does.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文