使用者在進行中的簡報中選取的項目。
const selection = SlidesApp.getActivePresentation().getSelection(); const currentPage = selection.getCurrentPage(); const selectionType = selection.getSelectionType();
方法
| 方法 | 傳回類型 | 簡短說明 |
|---|---|---|
get | Page|null | 如果沒有有效頁面,則傳回目前有效的 Page 或 null。 |
get | Page | 傳回所選 Page 執行個體的 Page 集合,如果未選取任何 Page 執行個體,則傳回 null。 |
get | Page | 傳回影格中選取的 Page 執行個體集合,或如果選取項目不是 Selection 類型,則傳回 null。Page |
get | Selection | 傳回 Selection。 |
get | Table | 傳回所選 Table 執行個體的 Table 集合,如果沒有選取任何 Table 執行個體,則傳回 null。 |
get | Text | 傳回所選的 Text,或如果選取項目不是 Selection 類型,則傳回 null。 |
內容詳盡的說明文件
get Current Page()
如果沒有有效頁面,則傳回目前有效的 Page 或 null。
const selection = SlidesApp.getActivePresentation().getSelection(); const currentPage = selection.getCurrentPage(); if (currentPage != null) { Logger.log(`Selected current active page ID: ${currentPage.getObjectId()}`); }
回攻員
Page|null
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
get Page Element Range()
傳回所選 Page 執行個體的 Page 集合,如果沒有選取任何 Page 執行個體,則傳回 null。
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}`); }
回攻員
Page
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
get Page Range()
傳回選取或 null 的 flimstrip 中 Page 執行個體的集合,如果選取項目不是 Selection 類型,則傳回 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}`, ); }
回攻員
Page
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
get Selection Type()
傳回 Selection。
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()}`); }
回攻員
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
get Table Cell Range()
傳回所選 Table 執行個體的 Table 集合,如果沒有選取任何 Table 執行個體,則傳回 null。
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}`); }
回攻員
Table
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
get Text Range()
傳回所選的 Text,或如果選取項目不是 Selection 類型,則傳回 null。
Text 代表兩種情況:
1. 選取的文字範圍。舉例來說,如果形狀含有「Hello」文字,且選取「He」,則傳回的範圍會是 Text = 0,且 Text = 2。
2. 游標位置。舉例來說,如果形狀含有「Hello」文字,且游標位於「H」之後 (「H|ello」),則傳回的範圍會是 Text = 1 和 Text = 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()}`); }
回攻員
Text
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations