You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Google Slides API移除文本高亮效果?

替换带高亮的文本并移除高亮效果

你可以直接在replaceAllText请求中添加样式配置,一次性完成文本替换和高亮移除,无需额外单独请求。通过textStyle字段里的clearBackgroundColor参数,就能清除目标文本的背景高亮颜色。

修改后的代码如下:

batch_requests_array = [
    {
        "replaceAllText": {
            "replaceText": "foo",
            "containsText": {
                "text": "bar",
                "matchCase": False
            },
            "textStyle": {
                "clearBackgroundColor": True
            }
        }
    }
]

batch_requests = {"requests": batch_requests_array}
request = slides_service.presentations().batchUpdate(presentationId=slides_id, body=batch_requests)
res = request.execute()

关键说明

  • clearBackgroundColor: True 会直接移除匹配文本的背景高亮样式,替换为无高亮的默认状态
  • 该请求会同时完成文本内容替换和样式清除,简化操作流程

内容的提问来源于stack exchange,提问作者MarcelD

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 01:55:19