AttributeError:“工作表”对象没有属性“插入行”

2024-09-30 12:27:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在关注Tim关于GoogleSheetsAPI的教程(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'

Tags: fromhttpsimportcomauthwww错误col
1条回答
网友
1楼 · 发布于 2024-09-30 12:27:39

我通过写sheet.append_row(insertUrl)修复了这个问题,问题是在末尾添加一个新行,您不能插入它。对我来说,这就是我所需要的一切,但是那些将问题和工作表叠加在一起的人。append_row()不会做这个把戏,我不知道该对你说什么

相关问题 更多 >

    热门问题