简体   繁体   English

如何使用 FindReplace 通过 Google API V4 Python 指定工作表名称

[英]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.

相关问题 将 pageToken 与 Google Analytics Reporting API v4 和 Python 结合使用 - Use of pageToken with Google Analytics Reporting API v4 and Python 如何通过python在单元格中使用Google sheet API V4插入注释 - How to use Google sheet API V4 insert note in cell by python 适用于Python的Google API v4 KeyError:“ _ module” - Google API v4 for Python KeyError: '_module' Python Google表格API v4:如何批量获取和批量更新Google表格? - Python Google Sheets API v4: How to do Batch Get and Batch Update Google sheets? 使用Google Safe Browsing API v4和Python请求发生意外响应 - Unexpected response with Google Safe Browsing API v4 and Python requests 使用Python在Google Sheets API v4中编写 - Writing in Google Sheets API v4 using Python 如何从Google Analytics Reporting API v4 Python获取前50个会话 - How to get Top 50 Sessions from Google Analytics Reporting API v4 Python 如何从Google Sheets API v4中的单元格获取格式信息的Python示例? - Python example of how to get formatting information from a cell in Google Sheets API v4? Google Analytics API v4 如何仅过滤目标 > 0 - Google Analytics API v4 how to filter only for goals > 0 如何在python中计算AWS API签名(v4)? - How can I calculate an AWS API signature (v4) in python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM