2
votes

I am not able to find the right way to update text of existing objects using the google slides API.

Currently I am deleting the slide and creating it again.

2

2 Answers

2
votes

How about using presentations.batchUpdate? By using this, the texts in the figures and on slide can be modified. The sample script is as follows. When you use this, please enable Slide API at API console and Advanced Google Services.

Sample script :

This sample modifies "sample text" on the slide of pageObjectIds to "updated text".

var presentationId = "### presentationId ###";
var resource = {
  "requests": [
    {
      "replaceAllText": {
        "containsText": {
          "text": "sample text"
        },
        "replaceText": "updated text",
        "pageObjectIds": ["### pageObjectIds ###"] // If this is not defined, the text is searched from all slides.
      }
    }
  ]
};
Slides.Presentations.batchUpdate(resource, presentationId);

If I misunderstand your question, I'm sorry.

1
votes

Inserting, deleting, or replacing text docs is what you're looking for.

There are two ways you can replace text in a presentation using the Slides API:

  1. By performing a global search-and-replace.
  2. By explicitly deleting and adding text. Both ways use the batchUpdate method, but with different request types.

Global search and replace

Use ReplaceAllTextRequest to do a global search-and-replace throughout your presentation.

The Text Merging section of the Merging Data guide provides an example of how you can use this request type.

Replacing text within a shape

The Slides API lets you modify the text content of a shape. You can remove individual ranges of text, and you can insert text at a specific location.

Use InsertTextRequest and DeleteTextRequest to perform these operations.