Class Selection

选择

用户在当前展示中的选择。

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

方法

方法返回类型简介
getCurrentPage()Page返回当前处于活动状态的 Page,如果没有活动页面,则返回 null
getPageElementRange()PageElementRange返回选择的 PageElement 实例的 PageElementRange 集合,如果未选择 PageElement 实例,则返回 null
getPageRange()PageRangePageRange 返回 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());
}

弃踢回攻

Page

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

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

弃踢回攻

PageElementRange

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

getPageRange()

PageRange 返回 flimstrip 中所选 Page 实例的集合,如果所选对象不是 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);
}
}

弃踢回攻

PageRange

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

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

弃踢回攻

SelectionType

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

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

弃踢回攻

TableCellRange

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

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

弃踢回攻

TextRange

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations