הבחירה של המשתמש במצגת הפעילה.
const selection = SlidesApp.getActivePresentation().getSelection(); const currentPage = selection.getCurrentPage(); const selectionType = selection.getSelectionType();
Methods
| שיטה | סוג הערך שמוחזר | תיאור קצר |
|---|---|---|
get | Page|null | מחזירה את Page או null שפעילים כרגע, אם אין דף פעיל. |
get | Page | הפונקציה מחזירה את אוסף Page של מופעי Page שנבחרו, או null אם לא נבחרו מופעי Page. |
get | Page | הפונקציה מחזירה את Page אוסף המופעים של Page ברצועת התמונות הממוזערות שנבחרו או null אם הבחירה לא מהסוג Selection. |
get | Selection | הפונקציה מחזירה את הערך Selection. |
get | Table | הפונקציה מחזירה את אוסף Table של מופעי Table שנבחרו או null אם לא נבחרו מופעי Table. |
get | Text | הפונקציה מחזירה את הערך Text שנבחר או את הערך null אם הבחירה היא לא מסוג Selection. |
תיעוד מפורט
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()}`); }
חזרה
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
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