如何通过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
相关产品推荐
相关产品推荐

