Class SlidesApp

  • The SlidesApp class allows you to programmatically create and manipulate Google Slides presentations using Apps Script.

  • You can open existing presentations using their ID or URL, or create new ones with a specified name.

  • SlidesApp provides access to various properties and methods for interacting with presentation elements like shapes, text, and slides.

  • It includes numerous enumerations for things like alignment, color types, and shape types to assist in customization.

  • SlidesApp also offers functionalities like getting the active presentation, building affine transformations, and accessing the user interface environment for adding menus and dialogs.

SlidesApp

Creates and opens Presentations that can be edited.

// Open a presentation by ID.
letpreso=SlidesApp.openById('PRESENTATION_ID_GOES_HERE');
// Create and open a presentation.
preso=SlidesApp.create('Presentation Name');

Properties

PropertyTypeDescription
AlignmentPositionAlignmentPosition An enumeration of the types of alignment positions.
ArrowStyleArrowStyle An enumeration of the different arrow styles that a Line can have.
AutoTextTypeAutoTextType An enumeration of the types of auto text.
AutofitTypeAutofitType An enumeration of autofit types.
CellMergeStateCellMergeState An enumeration of the different merge states of a table cell.
ColorTypeColorType An enumeration of color types.
ContentAlignmentContentAlignment An enumeration of values used to specify content alignment.
DashStyleDashStyle An enumeration of the different dash styles that a Line can have.
FillTypeFillType An enumeration of fill types.
LineCategoryLineCategory An enumeration of the categories of Line .
LineFillTypeLineFillType An enumeration of the types of LineFill .
LineTypeLineType An enumeration of the types of Line .
LinkTypeLinkType An enumeration of the types of links.
ListPresetListPreset An enumeration of the types of list presets.
PageBackgroundTypePageBackgroundType An enumeration of the types of page backgrounds.
PageElementTypePageElementType An enumeration of the types of page elements.
PageTypePageType An enumeration of the types of pages.
ParagraphAlignmentParagraphAlignment An enumeration of the types of paragraph alignment.
PlaceholderTypePlaceholderType An enumeration of the types of placeholders.
PredefinedLayoutPredefinedLayout An enumeration of the predefined layouts.
SelectionTypeSelectionType An enumeration of the types of selections.
ShapeTypeShapeType An enumeration of the types of shapes.
SheetsChartEmbedTypeSheetsChartEmbedType An enumeration of Sheets chart embed types.
SlideLinkingModeSlideLinkingMode An enumeration of the ways Slides can be linked.
SlidePositionSlidePosition An enumeration of the types of slide positions.
SpacingModeSpacingMode An enumeration of the types of spacing modes.
TextBaselineOffsetTextBaselineOffset An enumeration of the types of text baseline offset.
TextDirectionTextDirection An enumeration of the types of text directions.
ThemeColorTypeThemeColorType An enumeration of theme colors.
VideoSourceTypeVideoSourceType An enumeration of the types of video source.

Methods

MethodReturn typeBrief description
create(name) Presentation Creates and opens a new Presentation .
getActivePresentation() Presentation Returns the currently active presentation to which the script is container-bound, or null if there is no active presentation.
getUi() Ui Returns an instance of the presentation's user-interface environment that allows the script to add features like menus, dialogs, and sidebars.
newAffineTransformBuilder() AffineTransformBuilder Returns a new AffineTransformBuilder to build an AffineTransform .
openById(id) Presentation Opens the Presentation with the given ID.
openByUrl(url) Presentation Opens the Presentation with the given URL.

Detailed documentation

create(name)

Creates and opens a new Presentation .

Parameters

NameTypeDescription
nameStringThe name to be given to the created presentation.

Return

Presentation — the presentation with the given name.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://www.googleapis.com/auth/presentations

getActivePresentation()

Returns the currently active presentation to which the script is container-bound, or null if there is no active presentation. To interact with a presentation to which the script is not container-bound, use openById(id) instead.

// Get the current presentation to which this script is bound.
constpresentation=SlidesApp.getActivePresentation();
If the presentation is already open, the same presentation instance is returned.

Return

Presentation

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

getUi()

Returns an instance of the presentation's user-interface environment that allows the script to add features like menus, dialogs, and sidebars. A script can only interact with the UI for the current instance of an open presentation, and only if the script is bound to the presentation. For more information, see the guides to menus and dialogs and sidebars.

// Add a custom menu to the active presentation, including a separator and a
// sub-menu.
functiononOpen(e){
SlidesApp.getUi()
.createMenu('My Menu')
.addItem('My menu item','myFunction')
.addSeparator()
.addSubMenu(
SlidesApp.getUi()
.createMenu('My sub-menu')
.addItem('One sub-menu item','mySecondFunction')
.addItem('Another sub-menu item','myThirdFunction'),
)
.addToUi();
}

Return

Ui


newAffineTransformBuilder()

Returns a new AffineTransformBuilder to build an AffineTransform . The builder is preset with the identity affine transform.

Return

AffineTransformBuilder


openById(id)

Opens the Presentation with the given ID.

// Open a presentation by ID.
constpresentation=SlidesApp.openById('docId');
If the presentation is already open, the same presentation instance is returned.

Parameters

NameTypeDescription
idString

Return

Presentation — the presentation with the given ID

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://www.googleapis.com/auth/presentations

openByUrl(url)

Opens the Presentation with the given URL.

// Open a presentation by URL.
constpresentation=SlidesApp.openByUrl(
'https://docs.google.com/presentation/d/docId/edit',
);
If the presentation is already open, the same presentation instance is returned.

Parameters

NameTypeDescription
urlString

Return

Presentation — the presentation with the given URL

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://www.googleapis.com/auth/presentations

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2024年12月02日 UTC.