【发布时间】:2020-05-11 08:09:49
【问题描述】:
我有一个 python 脚本,它进行一些分析并将结果作为文本(段落)输出到 Google Doc 上。我知道如何通过 batchUpdate 插入文本、更新段落和文本样式。
doc_service.documents().batchUpdate(documentId=<ID>,body={'requests': <my_request>}).execute()
例如,“my_request”采用以下形式:
request = [
{
"insertText": {
"location": {
"index": <index_position>,
"segmentId": <id>
},
"text": <text>
}
},
{
"updateParagraphStyle": {
"paragraphStyle": {
"namedStyleType": <paragraph_type>
},
"range": {
"segmentId": <id>,
"startIndex": <index_position>,
"endIndex": <index_position>
},
"fields": "namedStyleType"
}
},
]
但是,一旦脚本完成更新表格,如果可以在文档顶部添加目录,那就太棒了。
但是,我对 Google Docs API 很陌生,我不完全确定如何去做。我知道我应该使用“TableOfContents”作为 StructuralElement。我也知道这个选项目前不会在每次修改文档后自动更新(这就是为什么我想在文档完成更新后创建它并将其放在文档顶部)。
如何用 python 做到这一点?我不清楚在我的请求中在哪里调用“TableOfContents”。
非常感谢!
【问题讨论】:
-
这里提供的答案将帮助您解决您的疑惑Insert table in Google Docs API Python
-
谢谢!不过,它并没有完全回答我的问题,因为我特别希望添加一个目录,而不仅仅是一个带有文本的表格。我需要一个表格,在完成后查看文档,记录标题、这些标题的链接和页码。