Class Selection

Seleção

A seleção do usuário na apresentação ativa.

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

Métodos

MétodoTipo de retornoBreve descrição
getCurrentPage()PageRetorna Page ou null ativo no momento se não houver uma página ativa.
getPageElementRange()PageElementRangeRetorna a coleção PageElementRange de instâncias PageElement selecionadas ou null se não houver instâncias PageElement selecionadas.
getPageRange()PageRangeRetornará ao PageRange uma coleção de instâncias Page na miniatura que são selecionadas ou null se a seleção não for do tipo SelectionType.PAGE.
getSelectionType()SelectionTypeRetorna o SelectionType.
getTableCellRange()TableCellRangeRetorna a coleção TableCellRange de instâncias TableCell selecionadas ou null se não houver instâncias TableCell selecionadas.
getTextRange()TextRangeRetorna o TextRange selecionado ou null se a seleção não for do tipo SelectionType.TEXT.

Documentação detalhada

getCurrentPage()

Retorna Page ou null ativo no momento se não houver uma página ativa.

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

Retorno

Page

Autorização

Os scripts que usam esse método exigem autorização com um ou mais dos seguintes escopos:

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

getPageElementRange()

Retorna a coleção PageElementRange de instâncias PageElement selecionadas ou null se não houver instâncias PageElement selecionadas.

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

Retorno

PageElementRange

Autorização

Os scripts que usam esse método exigem autorização com um ou mais dos seguintes escopos:

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

getPageRange()

Retornará ao PageRange uma coleção de instâncias Page na miniatura que são selecionadas ou null se a seleção não for do tipo SelectionType.PAGE.

var selection = SlidesApp.getActivePresentation().getSelection();
var selectionType = selection.getSelectionType();
if (selectionType == SlidesApp.SelectionType.PAGE) {
  var pageRange = selection.getPageRange();
  Logger.log('Number of pages in the flimstrip selected: ' + pageRange.getPages().length);
}
}

Retorno

PageRange

Autorização

Os scripts que usam esse método exigem autorização com um ou mais dos seguintes escopos:

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

getSelectionType()

Retorna o SelectionType.

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

Retorno

SelectionType

Autorização

Os scripts que usam esse método exigem autorização com um ou mais dos seguintes escopos:

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

getTableCellRange()

Retorna a coleção TableCellRange de instâncias TableCell selecionadas ou null se não houver instâncias TableCell selecionadas.

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

Retorno

TableCellRange

Autorização

Os scripts que usam esse método exigem autorização com um ou mais dos seguintes escopos:

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

getTextRange()

Retorna o TextRange selecionado ou null se a seleção não for do tipo SelectionType.TEXT.

O TextRange representa dois cenários:

1. Intervalo de texto selecionado. Por exemplo, se uma forma tiver o texto "Hello" e a opção "He" estiver selecionada, o intervalo retornado terá TextRange.getStartIndex() = 0 e TextRange.getEndIndex() = 2.

2. Posição do cursor. Por exemplo, se uma forma tiver o texto "Hello" e o cursor estiver depois de "H", ("H|ello"), o intervalo retornado terá TextRange.getStartIndex() = 1 e TextRange.getEndIndex() = 1.

var selection = SlidesApp.getActivePresentation().getSelection();
var selectionType = selection.getSelectionType();
if (selectionType == SlidesApp.SelectionType.TEXT) {
  var currentPage = selection.getCurrentPage();
  var pageElement = selection.getPageElementRange().getPageElements()[0];
  var textRange = selection.getTextRange();
  Logger.log('Text selected: ' + textRange.asString());
}

Retorno

TextRange

Autorização

Os scripts que usam esse método exigem autorização com um ou mais dos seguintes escopos:

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