Class Selection

Zaznaczenie

Wybór użytkownika w aktywnej prezentacji.

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

Metody

MetodaZwracany typKrótki opis
getCurrentPage()PageJeśli nie ma aktywnej strony, zwraca obecnie aktywną stronę Page lub null.
getPageElementRange()PageElementRangeZwraca zbiór PageElementRange wybranych instancji (PageElement) lub null, jeśli nie wybrano żadnych instancji PageElement.
getPageRange()PageRangeZwraca PageRange zbiór wybranych Page instancji w flimstrip, lub null, jeśli wybór nie jest typu SelectionType.PAGE.
getSelectionType()SelectionTypeZwraca wartość SelectionType.
getTableCellRange()TableCellRangeZwraca zbiór TableCellRange wybranych instancji TableCell lub zbiór null, jeśli nie wybrano TableCell instancji.
getTextRange()TextRangeZwraca podaną wartość TextRange lub null, jeśli wybór nie jest typu SelectionType.TEXT.

Szczegółowa dokumentacja

getCurrentPage()

Jeśli nie ma aktywnej strony, zwraca obecnie aktywną stronę Page lub null.

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

Powroty

Page

Upoważnienie

Skrypty korzystające z tej metody wymagają autoryzacji z co najmniej jednym z tych zakresów:

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

getPageElementRange()

Zwraca zbiór PageElementRange wybranych instancji (PageElement) lub null, jeśli nie wybrano żadnych instancji PageElement.

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);
}

Powroty

PageElementRange

Upoważnienie

Skrypty korzystające z tej metody wymagają autoryzacji z co najmniej jednym z tych zakresów:

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

getPageRange()

Zwraca PageRange zbiór wybranych Page instancji w flimstrip, lub null, jeśli wybór nie jest typu 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);
}
}

Powroty

PageRange

Upoważnienie

Skrypty korzystające z tej metody wymagają autoryzacji z co najmniej jednym z tych zakresów:

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

getSelectionType()

Zwraca wartość 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());
}

Powroty

SelectionType

Upoważnienie

Skrypty korzystające z tej metody wymagają autoryzacji z co najmniej jednym z tych zakresów:

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

getTableCellRange()

Zwraca zbiór TableCellRange wybranych instancji TableCell lub zbiór null, jeśli nie wybrano TableCell instancji.

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);
}

Powroty

TableCellRange

Upoważnienie

Skrypty korzystające z tej metody wymagają autoryzacji z co najmniej jednym z tych zakresów:

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

getTextRange()

Zwraca podaną wartość TextRange lub null, jeśli wybór nie jest typu SelectionType.TEXT.

TextRange odpowiada 2 przykładom:

1. Zaznaczono zakres tekstu. Jeśli na przykład kształt zawiera tekst „Hello” i wybrano „He”, zwrócony zakres ma TextRange.getStartIndex() = 0, a TextRange.getEndIndex() = 2.

2. Pozycja kursora. Na przykład jeśli kształt w kształcie zawiera tekst „Hello”, a kursor znajduje się po literze „H”, ("H|ello"), zwracany zakres ma TextRange.getStartIndex() = 1, a 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());
}

Powroty

TextRange

Upoważnienie

Skrypty korzystające z tej metody wymagają autoryzacji z co najmniej jednym z tych zakresów:

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