首页 > 解决方案 > AttributeError:“工作表”对象没有属性“插入行”

问题描述

我一直在关注 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'

标签: pythongoogle-sheetsgoogle-api

解决方案


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


推荐阅读