Pilihan pengguna dalam presentasi yang aktif.
const selection = SlidesApp.getActivePresentation().getSelection(); const currentPage = selection.getCurrentPage(); const selectionType = selection.getSelectionType();
Metode
| Metode | Jenis nilai yang ditampilkan | Deskripsi singkat |
|---|---|---|
get | Page|null | Menampilkan Page yang saat ini aktif atau null jika tidak ada halaman yang aktif. |
get | Page | Menampilkan koleksi Page dari instance Page yang dipilih atau null jika tidak ada instance Page yang dipilih. |
get | Page | Menampilkan Page kumpulan instance Page dalam filmstrip yang dipilih atau null jika pilihan bukan berjenis Selection. |
get | Selection | Menampilkan Selection. |
get | Table | Menampilkan kumpulan Table dari instance Table yang dipilih
atau null jika tidak ada instance Table yang dipilih. |
get | Text | Menampilkan Text yang dipilih atau null jika pilihan bukan berjenis
Selection. |
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 filmstrip 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
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