[英]How to use FindReplace for specify sheetname by Google API V4 Python
I would like to use Python to update the filename and spreadsheet ID saved in a Google Sheet when I upload files to my Drive according to the sheetName
in the Sheet, and I want to delete or replace a row with a duplicate name when I upload my files (so that the newest file ID is updated with same date).当我根据Sheet中的
sheetName
将文件上传到我的云端硬盘时,我想使用Python来更新保存在Google Sheet中的文件名和电子表格ID,并且我想在上传时删除或替换具有重复名称的行文件(以便最新的文件 ID 更新为同一日期)。
I have been using batchUpdate , but I can only replace the same column but not the same row, and only in the first sheet of my spreadsheet.我一直在使用batchUpdate ,但我只能替换同一列但不能替换同一行,并且只能在我的电子表格的第一张表中。
Here's the script:这是脚本:
#file_name and file_ID: obtain when upload the files,
def update(file_name, file_ID):
range_name = file_name + "!A:B"
requests = []
requests.append([{
"findReplace": {
"find": Date,
"replacement": FileID,
"matchCase": True,
"matchEntireCell": True,
"searchByRegex": True,
"range": {
"sheetId": 0,
"startColumnIndex": 0,
"endColumnIndex": 1
},
}
}])
body = {"requests": [requests]}
response = service.spreadsheets().batchUpdate(
spreadsheetId=spreadsheet_id, body=body).execute()
pprint(response)
Is there any way I can use to find if the name is column A in the "filetype1" sheet (need match the Sheet Name to determine under which sheet first), then replace the ID in column B?有什么方法可以用来查找名称是否是“filetype1”工作表中的 A 列(需要匹配工作表名称以确定首先在哪个工作表下),然后替换 B 列中的 ID?
I comprehend that you have a table where you want to search for a Date
and change its ID
value of the same row.我理解您有一个表,您想在其中搜索
Date
并更改其同一行的ID
值。 If understood it correctly, you would need to use Values.get()
and Values.update()
methods.如果理解正确,您将需要使用
Values.get()
和Values.update()
方法。
First you will need to use get
to read the full table.首先,您需要使用
get
来阅读完整的表格。 Parse it with Python and substitute the appropriate values.用 Python 解析它并替换适当的值。 After that operation you can upload the full table as an
update
request.完成该操作后,您可以将完整表作为
update
请求上传。 Please, don't hesitate to ask me any follow-up questions.请不要犹豫,问我任何后续问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.