使用者在使用簡報中的選取項目。
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 | 傳回已選取 Flimstrip 中的 Page 例項集合 PageRange ;如果選項並非 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()
傳回已選取 Flimstrip 中的 Page
例項集合 PageRange
;如果選取項目不是 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