Class Selection

בחירה

הבחירה של המשתמש במצגת הפעילה.

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

Methods

שיטהסוג הערך שמוחזרתיאור קצר
getCurrentPage()Page|nullמחזירה את Page או null שפעילים כרגע, אם אין דף פעיל.
getPageElementRange()PageElementRange|nullהפונקציה מחזירה את אוסף PageElementRange של מופעי PageElement שנבחרו, או null אם לא נבחרו מופעי PageElement.
getPageRange()PageRange|nullהפונקציה מחזירה את PageRange אוסף של Page מופעים ברצועת התמונות הממוזערות שנבחרו או null אם הבחירה לא מהסוג SelectionType.PAGE.
getSelectionType()SelectionTypeהפונקציה מחזירה את הערך SelectionType.
getTableCellRange()TableCellRange|nullהפונקציה מחזירה את אוסף TableCellRange של מופעי TableCell שנבחרו או null אם לא נבחרו מופעי TableCell.
getTextRange()TextRange|nullהפונקציה מחזירה את הערך TextRange שנבחר או את הערך null אם הבחירה היא לא מסוג SelectionType.TEXT.

תיעוד מפורט

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

אישור

סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:

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

getPageElementRange()

הפונקציה מחזירה את אוסף PageElementRange של מופעי PageElement שנבחרו, או null אם לא נבחרו מופעי PageElement.

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

אישור

סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:

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

getPageRange()

הפונקציה מחזירה את PageRange אוסף של Page מופעים ברצועת התמונות הממוזערות שנבחרו או null אם הבחירה לא מהסוג SelectionType.PAGE.

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

אישור

סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:

  • 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

אישור

סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:

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

getTableCellRange()

הפונקציה מחזירה את אוסף TableCellRange של מופעי TableCell שנבחרו או null אם לא נבחרו מופעי TableCell.

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

אישור

סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:

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

getTextRange()

הפונקציה מחזירה את הערך TextRange שנבחר או את הערך null אם הבחירה היא לא מסוג SelectionType.TEXT.

הערך TextRange מייצג שני תרחישים:

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

אישור

סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:

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