Class Selection

選択

現在共有中の画面でユーザーが選択した内容。

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

メソッド

メソッド戻り値の型概要
getCurrentPage()Page|null現在アクティブな Page を返します。アクティブなページがない場合は null を返します。
getPageElementRange()PageElementRange|null選択された PageElement インスタンスの PageElementRange コレクションを返します。PageElement インスタンスが選択されていない場合は null を返します。
getPageRange()PageRange|null選択されたフィルムストリップ内の Page インスタンスのコレクションである PageRange を返します。選択が SelectionType.PAGE 型でない場合は null を返します。
getSelectionType()SelectionTypeSelectionType を返します。
getTableCellRange()TableCellRange|null選択された TableCell インスタンスの TableCellRange コレクションを返します。TableCell インスタンスが選択されていない場合は null を返します。
getTextRange()TextRange|null選択された TextRange を返します。選択が SelectionType.TEXT 型でない場合は 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()}`);
}

戻る

SelectionType

承認

このメソッドを使用するスクリプトには、次の 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