Class Selection

Pilihan

Pilihan pengguna dalam presentasi aktif.

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

Metode

MetodeJenis hasil yang ditampilkanDeskripsi singkat
getCurrentPage()Page|nullMenampilkan Page yang saat ini aktif atau null jika tidak ada halaman yang aktif.
getPageElementRange()PageElementRange|nullMenampilkan koleksi PageElementRange dari instance PageElement yang dipilih atau null jika tidak ada instance PageElement yang dipilih.
getPageRange()PageRange|nullMenampilkan PageRange kumpulan instance Page dalam flimstrip yang dipilih atau null jika pilihan bukan berjenis SelectionType.PAGE.
getSelectionType()SelectionTypeMenampilkan SelectionType.
getTableCellRange()TableCellRange|nullMenampilkan kumpulan TableCellRange dari instance TableCell yang dipilih atau null jika tidak ada instance TableCell yang dipilih.
getTextRange()TextRange|nullMenampilkan TextRange yang dipilih atau null jika pilihan bukan berjenis SelectionType.TEXT.

Dokumentasi mendetail

getCurrentPage()

Menampilkan Page yang saat ini aktif atau null jika tidak ada halaman yang aktif.

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

Pulang pergi

Page|null

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 dari instance PageElement yang dipilih atau null jika tidak ada instance PageElement yang dipilih.

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

Pulang pergi

PageElementRange|null

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 pilihan bukan berjenis SelectionType.PAGE.

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

Pulang pergi

PageRange|null

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.

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

Pulang pergi

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 dari instance TableCell yang dipilih atau null jika tidak ada instance TableCell yang dipilih.

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

Pulang pergi

TableCellRange|null

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 berjenis SelectionType.TEXT.

TextRange mewakili dua skenario:

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

2. Posisi kursor. Misalnya, jika bentuk memiliki teks "Hello", dan kursor berada setelah "H", ("H|ello"), rentang yang ditampilkan memiliki TextRange.getStartIndex() = 1 dan TextRange.getEndIndex() = 1.

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

Pulang pergi

TextRange|null

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