【问题标题】:AttributeError: 'Worksheet' object has no attribute 'insert_row'AttributeError:“工作表”对象没有属性“插入行”
【发布时间】:2020-08-15 22:01:58
【问题描述】:

我一直在关注 Tim 关于 Google Sheets API 的教程 (https://www.youtube.com/watch?v=cnPlKLEGR7E) 当我到达sheet.insert_row(insertRow, 9) 行时,它显示了一个错误, 所有其他的东西都工作得很好。 重要的是,蒂姆没有遇到同样的问题。

代码:

import gspread
from oauth2client.service_account import ServiceAccountCredentials
from pprint import pprint

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("Raz.json", scope)

client = gspread.authorize(creds)

sheet = client.open("RandomRaz").sheet1


row = sheet.row_values(3)
col = sheet.col_values(2)
cell = sheet.cell(1,2).value
insertRow = ["Test#123", "Url!"]
sheet.insert_row(insertRow, 9)
pprint(len(col))

错误:

Traceback (most recent call last):
  File "/Users/#######/PycharmProjects/pythonProject/x.py", line 19, in <module>
    sheet.insert_row(insertRow, 9)
AttributeError: 'Worksheet' object has no attribute 'insert_row'

【问题讨论】:

  • 你用的是什么版本的gspread?

标签: python google-sheets google-api


【解决方案1】:

我通过写sheet.append_row(insertUrl) 解决了这个问题,问题是它在最后添加了一个新行,你不能插入它。对我来说,这就是我所需要的,但是会遇到同样问题的人,而 sheet.append_row() 不会成功,我不知道该对你说什么

【讨论】:

    猜你喜欢
    • 2020-12-09
    • 1970-01-01
    • 2021-09-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-01
    • 2018-05-26
    • 1970-01-01
    • 2019-10-22
    相关资源
    最近更新 更多