python - 如何使用 google docs api (Python) 更新 google doc

标签 python json google-docs-api

我是 Google 文档 API 的新手,希望能够使用 ReplaceText 选项添加文本。我该如何设置呢?我在 Python 3.6 中这样做

最佳答案

只需按照 Google Docs API quickstart 中的步骤操作即可使用Python。然后尝试运行此代码以使用 InsertTextRequest 插入文本方法:

requests = [
     {
        'insertText': {
            'location': {
                'index': 25,
            },
            'text': text1
        }
    },
             {
        'insertText': {
            'location': {
                'index': 50,
            },
            'text': text2
        }
    },
             {
        'insertText': {
            'location': {
                'index': 75,
            },
            'text': text3
        }
    },
]

result = service.documents().batchUpdate(
    documentId=DOCUMENT_ID, body={'requests': requests}).execute()

要将文本插入到文档中,请使用 BatchUpdate 方法并包含一个 InsertTextRequest,其中文本和位置作为负载。最好使用文档中建议的方法。

关于python - 如何使用 google docs api (Python) 更新 google doc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55371601/

相关文章:

python - Sklearn set_params 正好接受 1 个参数?

python - Scapy ARP 函数在运行时未给出正确的输出

python - 如何使用日志记录模块记录我的进程ID

python - 使用字典时如何避免 KeyError?

json - Firebase 安全规则?

json - 处理来自服务器,JSON的数据时出现Swift错误

ios - 如何在 swift 3 中以编程方式向 UITableView 添加部分

google-docs-api - 如何解决使用 Google Apps 脚本从集合中删除资源时出现的 ETag 错误

javascript - 通过 Google 文档中的脚本修改表

google-drive-api - 下载 HTML 格式的 Google 文档电子表格