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 saat ini aktif jika tidak ada halaman yang aktif.
getPageElementRange()PageElementRangeMenampilkan koleksi PageElementRange instance PageElement yang dipilih atau null jika tidak ada instance PageElement yang dipilih.
getPageRange()PageRangeMenampilkan kumpulan PageRange instance Page di flimstrip yang dipilih, atau null jika pilihannya bukan jenis SelectionType.PAGE.
getSelectionType()SelectionTypeMenampilkan SelectionType.
getTableCellRange()TableCellRangeMenampilkan koleksi TableCellRange instance TableCell yang dipilih atau null jika tidak ada instance TableCell yang dipilih.
getTextRange()TextRangeMenampilkan TextRange yang dipilih atau null jika pilihannya tidak berjenis SelectionType.TEXT.

Dokumentasi mendetail

getCurrentPage()

Menampilkan Page atau null yang saat ini 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 koleksi 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 kumpulan PageRange instance Page di 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 koleksi 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 pilihannya tidak berjenis SelectionType.TEXT.

TextRange mewakili dua skenario:

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

2. Posisi kursor. Misalnya, jika sebuah bentuk memiliki teks "Halo", dan kursor berada 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