アクティブなプレゼンテーションでのユーザーの選択。
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
承認
このメソッドを使用するスクリプトには、次の 1 つ以上の スコープでの承認が必要です。
-
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
承認
このメソッドを使用するスクリプトには、次の 1 つ以上の スコープでの承認が必要です。
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
getPageRange()
選択されているフィルムストリップ内の Page インスタンスの PageRange コレクションを返します。選択が 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
承認
このメソッドを使用するスクリプトには、次の 1 つ以上の スコープでの承認が必要です。
-
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()}`); }
戻る
承認
このメソッドを使用するスクリプトには、次の 1 つ以上の スコープでの承認が必要です。
-
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
承認
このメソッドを使用するスクリプトには、次の 1 つ以上の スコープでの承認が必要です。
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
getTextRange()
選択されている TextRange を返します。選択が SelectionType.TEXT 型でない場合は null を返します。
TextRange は次の 2 つのシナリオを表します。
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
承認
このメソッドを使用するスクリプトには、次の 1 つ以上の スコープでの承認が必要です。
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations