有没有一种方法可以使用 google doc API 将文本替换为带样式的文本?

Is there a way to replace text by a styled text using google doc API?

[ReplaceAllTextRequest] 文档1

我好像只能用另一个纯文本替换一个纯文本?

我可以在替换中添加格式吗?例如使替换为红色+粗体

目前无法使用文档 API 用带样式的文本替换文本。

作为解决方法,您可以:

  1. GET文件的全部内容。

  2. 查找将被替换的文档范围(查找要替换的文本匹配项)。在发出 ReplaceAllTextRequest 请求后重新计算替换文本的范围。

  3. 发出 ReplaceAllTextRequest 请求。
  4. 使用在步骤 2 中计算的范围,发出所有适当的 UpdateTextStyleRequest requests. All this requests can be sent as a single batchUpdate 请求。