用户在当前演示文稿中的选择内容。
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 实例的 Page 集合;如果选择内容不是 Selection 类型,则返回 null。 |
get | Selection | 返回 Selection。 |
get | Table | 返回所选 Table 实例的 Table 集合;如果没有选择任何 Table 实例,则返回 null。 |
get | Text | 返回所选 Text;如果选择内容不是
Selection 类型,则返回 null。 |
详细文档
getCurrentPage()
返回当前活跃的 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
getPageElementRange()
返回所选 PageElement 实例的 PageElementRange 集合;如果没有选择任何 PageElement 实例,则返回 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}`); }
返回
PageElementRange|null
授权
使用此方法需要获得以下一个或多个范围的授权的脚本:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
getPageRange()
返回所选幻灯片缩略图中的 PageRange 实例的 Page 集合;如果选择内容不是 SelectionType.PAGE 类型,则返回 null。
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}`, ); }
返回
PageRange|null
授权
使用此方法需要获得以下一个或多个范围的授权的脚本:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
getSelectionType()
返回 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()}`); }
返回
授权
使用此方法需要获得以下一个或多个范围的授权的脚本:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
getTableCellRange()
返回所选 TableCell 实例的 TableCellRange 集合;如果没有选择任何 TableCell 实例,则返回 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}`); }
返回
TableCellRange|null
授权
使用此方法需要获得以下一个或多个范围的授权的脚本:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
getTextRange()
返回所选 TextRange;如果选择内容不是 SelectionType.TEXT 类型,则返回 null。
TextRange 表示以下两种情况:
1. 所选文本范围。例如,如果某个形状包含文本“Hello”,并且选择了“He”,
则返回的范围具有 TextRange.getStartIndex() = 0 和 TextRange.getEndIndex() =
2。
2. 光标位置。例如,如果某个形状包含文本“Hello”,并且光标位于“H”之后(“H|ello”),则返回的范围具有 TextRange.getStartIndex() = 1 和 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()}`); }
返回
TextRange|null
授权
使用此方法需要获得以下一个或多个范围的授权的脚本:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations