用户在当前演示文稿中的选择。
var selection = SlidesApp.getActivePresentation().getSelection(); var currentPage = selection.getCurrentPage(); var selectionType = selection.getSelectionType(); }
方法
方法 | 返回类型 | 简介 |
---|---|---|
getCurrentPage() | Page | 返回当前处于活跃状态的 Page 或 null (如果没有活跃网页)。 |
getPageElementRange() | PageElementRange | 返回所选的 PageElement 实例的 PageElementRange 集合;如果未选择 PageElement 实例,则返回 null 。 |
getPageRange() | PageRange | 返回 PageRange 选中的 Flimstrip 中 Page 实例的集合;如果所选对象的类型不是 SelectionType.PAGE ,则返回 null 。 |
getSelectionType() | SelectionType | 返回 SelectionType 。 |
getTableCellRange() | TableCellRange | 返回所选的 TableCell 实例的 TableCellRange 集合;如果未选择 TableCell 实例,则返回 null 。 |
getTextRange() | TextRange | 返回所选 TextRange ;如果所选内容的类型不是 SelectionType.TEXT ,则返回 null 。 |
详细文档
getCurrentPage()
返回当前有效的 Page
或 null
(如果没有有效网页)。
var selection = SlidesApp.getActivePresentation().getSelection(); var currentPage = selection.getCurrentPage(); if (currentPage != null) { Logger.log('Selected current active page ID: ' + currentPage.getObjectId()); }
返回
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
getPageElementRange()
返回所选的 PageElement
实例的 PageElementRange
集合;如果未选择 PageElement
实例,则返回 null
。
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); }
返回
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
getPageRange()
返回 PageRange
选中的 Flimstrip 中一系列实例;如果所选对象不是SelectionType.PAGE
类型,则返回null
。
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); } }
返回
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
getSelectionType()
返回 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()); }
返回
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
getTableCellRange()
返回所选的 TableCell
实例的 TableCellRange
集合;如果未选择 TableCell
实例,则返回 null
。
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); }
返回
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
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。
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()); }
返回
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations