python - 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'
解决方案
我通过写作解决了这个问题sheet.append_row(insertUrl)
,问题是它在最后添加了一个新行,你不能插入它。对我来说,这就是我所需要的,但是会遇到同样问题的人,而 sheet.append_row() 不会成功我不知道该对你说什么
推荐阅读
- android - 在没有互联网的情况下从 WLAN 请求下载时,Android 9 无法开始下载
- python - 尝试从导入的模块中引用会话时,SQLAlchemy '没有这样的表'
- swift - Keyboard does not resign from view
- javascript - Importrange 使用脚本一次更改多个电子表格中的单元格
- encoding - 如何将 NSIS 中的字符串编码为 UTF-16LE 格式?
- python - 图像检测的嵌套循环需要永远运行 1 亿次
- javascript - 正则表达式仅匹配第一次或仅第二次出现
- php - 删除模型时分离数据透视表中模型的每条记录
- c++ - 在 Windows C++ 中更新进度条
- perl - 单个语句中的后增量和变量重用,Perl 5 与 Perl 6