如何使用Python导入CSV删除或更新Google电子表格?
我正在处理我的Python脚本,现在我的脚本可以将CSV导入电子表格,但是我必须对其进行修改以替换或删除已经导入的旧电子表格并将其更新为最新的CSV,因为当前我的脚本仅在上传和在CSV文件上的数据粘贴。我需要修改脚本什么?
我的脚本
def export_csv(o_csv, sheet_id):
with open(o_csv, 'r') as csv_file:
csvContents = csv_file.read()
body = {
'requests': [{
'pasteData': {
"coordinate": {
"sheetId": sheet_id,
"rowIndex": "0",
"columnIndex": "0",
},
"data": csvContents,
"type": 'PASTE_NORMAL',
"delimiter": ',',
}
}]
}
I'm working on my Python script and right now my script can import csv to spreadsheet, but I have to modify it to replace or delete the old spreadsheet that already imported and update it to the latest csv, since currently my script only working in upload and normal paste of data on csv file. What do I need to modify my script?
My script
def export_csv(o_csv, sheet_id):
with open(o_csv, 'r') as csv_file:
csvContents = csv_file.read()
body = {
'requests': [{
'pasteData': {
"coordinate": {
"sheetId": sheet_id,
"rowIndex": "0",
"columnIndex": "0",
},
"data": csvContents,
"type": 'PASTE_NORMAL',
"delimiter": ',',
}
}]
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信您的目标如下。
Sheet_id
的表之后,您要将CSV数据放在Sheet_id
的表格上。在这种情况下,以下修改如何?
来自:
到:
Sheet_id
的表格。并且,清除工作表后,将放置CSV数据。这样,可以通过一个API调用来完成此请求。字段
使用*
。如果要控制清晰的内容,请修改此内容。参考:
I believe your goal is as follows.
sheet_id
is cleared, you want to put the CSV data to the sheet ofsheet_id
.In this case, how about the following modification?
From:
To:
sheet_id
is cleared. And, after the sheet was cleared, the CSV data is put. By this, this request can be done by one API call.fields
use*
. If you want to control the clear contents, please modify this.References: