简体   繁体   中英

Is there a way to replace text with a suggestion in Google Docs using Apps Script?

I'm trying to write a script that takes a string in a document in Google Docs and replaces it. The caveat is that I want to replace it using Google Docs suggestion mode, not only change the whole text, which gives my collaborators the option to accept the suggestion or reject it and get the text back to the original form. This is a built-in feature in Google Docs, but I couldn't find a way of using it through apps script.

Currently I'm using the code below:

var docBody = DocumentApp.getActiveDocument()
  .getBody();

  docBody.replaceText('Hi guys, as you can see, this video is a preview,', 'Oi pessoal, como você pode ver, este vídeo é uma prévia,'); 

But this is replacing the text, and I'd like to just suggest the second part (the part in Portuguese).

Is there any way to do that?

No, the Google Docs API does not implement a way to create suggestions or comments [1].

You can get the suggestions made in a document doing a get request [2] but not insert them. Also you can get the different versions of a document (one version for each time you save the document) doing a get request with the Drive API [3].

[1] https://developers.google.com/docs/api/reference/rest/v1/documents/request

[2] https://developers.google.com/docs/api/how-tos/suggestions

[2] https://developers.google.com/drive/api/v3/reference/revisions/get

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM