Class Selection

Pilihan

Pilihan pengguna dalam presentasi aktif.

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

Metode

MetodeJenis hasil yang ditampilkanDeskripsi singkat
getCurrentPage()PageMenampilkan Page atau null yang sedang aktif jika tidak ada halaman yang aktif.
getPageElementRange()PageElementRangeMenampilkan kumpulan PageElementRange instance PageElement yang dipilih atau null jika tidak ada instance PageElement yang dipilih.
getPageRange()PageRangeMenampilkan PageRange kumpulan instance Page dalam flimstrip yang dipilih atau null jika pilihannya bukan jenis SelectionType.PAGE.
getSelectionType()SelectionTypeMenampilkan SelectionType.
getTableCellRange()TableCellRangeMenampilkan kumpulan TableCellRange instance TableCell yang dipilih atau null jika tidak ada instance TableCell yang dipilih.
getTextRange()TextRangeMenampilkan TextRange yang dipilih atau null jika pilihan bukan jenis SelectionType.TEXT.

Dokumentasi mendetail

getCurrentPage()

Menampilkan Page atau null yang sedang aktif jika tidak ada halaman yang aktif.

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

Return

Page

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

getPageElementRange()

Menampilkan kumpulan PageElementRange instance PageElement yang dipilih atau null jika tidak ada instance PageElement yang dipilih.

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

Return

PageElementRange

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

getPageRange()

Menampilkan PageRange kumpulan instance Page dalam flimstrip yang dipilih atau null jika pilihannya bukan jenis 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);
}
}

Return

PageRange

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

getSelectionType()

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

Return

SelectionType

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

getTableCellRange()

Menampilkan kumpulan TableCellRange instance TableCell yang dipilih atau null jika tidak ada instance TableCell yang dipilih.

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

Return

TableCellRange

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

getTextRange()

Menampilkan TextRange yang dipilih atau null jika pilihan bukan jenis SelectionType.TEXT.

TextRange mewakili dua skenario:

1. Rentang teks dipilih. Misalnya, jika sebuah bentuk memiliki teks "Halo", dan "He" dipilih, rentang yang ditampilkan memiliki TextRange.getStartIndex() = 0, dan TextRange.getEndIndex() = 2.

2. Posisi kursor. Misalnya, jika bentuk memiliki teks "Halo", dan kursor terletak setelah "H", ("H|ello"), rentang yang ditampilkan memiliki TextRange.getStartIndex() = 1 dan 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());
}

Return

TextRange

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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