Class Selection  |  Apps Script  |  Google for Developers (original) (raw)

Class Selection

Stay organized with collections Save and categorize content based on your preferences.

Selection

The user's selection in the active presentation.

const selection = SlidesApp.getActivePresentation().getSelection(); const currentPage = selection.getCurrentPage(); const selectionType = selection.getSelectionType();

Detailed documentation

getCurrentPage()

Returns the currently active [Page](/apps-script/reference/slides/page) or null if there is no active page.

const selection = SlidesApp.getActivePresentation().getSelection(); const currentPage = selection.getCurrentPage(); if (currentPage != null) { Logger.log(Selected current active page ID: ${currentPage.getObjectId()}); }

Return

[Page](/apps-script/reference/slides/page)

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


getPageElementRange()

Returns the [PageElementRange](/apps-script/reference/slides/page-element-range) collection of [PageElement](/apps-script/reference/slides/page-element) instances that are selected or null if there are no [PageElement](/apps-script/reference/slides/page-element) instances selected.

const selection = SlidesApp.getActivePresentation().getSelection(); const selectionType = selection.getSelectionType(); if (selectionType === SlidesApp.SelectionType.PAGE_ELEMENT) { const currentPage = selection.getCurrentPage(); const pageElements = selection.getPageElementRange().getPageElements(); Logger.log(Number of page elements selected: ${pageElements.length}); }

Return

[PageElementRange](/apps-script/reference/slides/page-element-range)

Authorization

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



getSelectionType()

Returns the [SelectionType](/apps-script/reference/slides/selection-type).

const selection = SlidesApp.getActivePresentation().getSelection(); const selectionType = selection.getSelectionType(); if (selectionType === SlidesApp.SelectionType.CURRENT_PAGE) { const currentPage = selection.getCurrentPage(); Logger.log(Selected current active page ID: ${currentPage.getObjectId()}); }

Return

[SelectionType](/apps-script/reference/slides/selection-type)

Authorization

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


getTableCellRange()

Returns the [TableCellRange](/apps-script/reference/slides/table-cell-range) collection of [TableCell](/apps-script/reference/slides/table-cell) instances that are selected or null if there are no [TableCell](/apps-script/reference/slides/table-cell) instances selected.

const selection = SlidesApp.getActivePresentation().getSelection(); const selectionType = selection.getSelectionType(); if (selectionType === SlidesApp.SelectionType.TABLE_CELL) { const currentPage = selection.getCurrentPage(); const tableCells = selection.getTableCellRange().getTableCells(); const table = tableCells[0].getParentTable(); Logger.log(Number of table cells selected: ${tableCells.length}); }

Return

[TableCellRange](/apps-script/reference/slides/table-cell-range)

Authorization

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


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.