The Advanced Slides service lets you access the Slides API using Apps Script. This service allows scripts to read and edit content in Google Slides.
Reference
For detailed information on this service, see the reference documentation for the Slides API. Like all advanced services in Apps Script, the advanced Slides service uses the same objects, methods, and parameters as the public API. For more information, see How method signatures are determined.
To report issues and find other support, see the Slides support guide.
Sample code
The sample code below uses version 1 of the API.
Create a new presentation
The following example demonstrates how to create a new presentation using the Slides advanced service. It is equivalent to the Create a new presentation recipe sample.
Create a new slide
The following example demonstrates how to create a new slide in a presentation, at a specific index and with predefined layout. It is equivalent to the Create a new slide recipe sample.
Read page element object IDs
The following example demonstrates how to retrieve the object IDs for every page element on a specific slide using a field mask. It is equivalent to the Read element object IDs from a page recipe sample.
Add a new text box
The following example demonstrates how to add a new text box to a slide and add text to it. It is equivalent to the Add a text box to a slide recipe sample.
Format shape text
The following example demonstrates how to format a shape's text, updating its color, font and underlining its text. It is equivalent to the Format text in a shape or textbox recipe sample.
Best Practices
Batch Updates
When using the Slides Advanced Service, combine multiple requests in an array
rather than calling batchUpdate
in a loop.
Don't — Call batchUpdate
in a loop.
var titles = ["slide 1", "slide 2"];
for (var i = 0; i < titles.length; i++) {
Slides.Presentations.batchUpdate(preso, {
requests: [{
createSlide: ...
}]
});
}
Do — Call batchUpdate
with an array of
updates.
var requests = [];
var titles = ["slide 1", "slide 2"];
for (var i = 0; i < titles.length; i++) {
requests.push({ createSlide: ... });
}
Slides.Presentations.batchUpdate(preso, {
requests: requests
});