Lựa chọn của người dùng trong bản trình bày đang hoạt động.
const selection = SlidesApp.getActivePresentation().getSelection(); const currentPage = selection.getCurrentPage(); const selectionType = selection.getSelectionType();
Phương thức
| Phương thức | Kiểu dữ liệu trả về | Mô tả ngắn |
|---|---|---|
get | Page|null | Trả về Page hoặc null hiện đang hoạt động nếu không có trang nào đang hoạt động. |
get | Page | Trả về tập hợp Page của các phiên bản Page được chọn hoặc null nếu không có phiên bản Page nào được chọn. |
get | Page | Trả về Page một tập hợp các thực thể Page trong dải băng được chọn hoặc null nếu lựa chọn không thuộc loại Selection. |
get | Selection | Trả về Selection. |
get | Table | Trả về tập hợp Table gồm các thực thể Table được chọn hoặc null nếu không có thực thể Table nào được chọn. |
get | Text | Trả về Text đã chọn hoặc null nếu lựa chọn không thuộc loại Selection. |
Tài liệu chi tiết
getCurrentPage()
Trả về Page hoặc null hiện đang hoạt động nếu không có trang nào đang hoạt động.
const selection = SlidesApp.getActivePresentation().getSelection(); const currentPage = selection.getCurrentPage(); if (currentPage != null) { Logger.log(`Selected current active page ID: ${currentPage.getObjectId()}`); }
Cầu thủ trả bóng
Page|null
Ủy quyền
Các tập lệnh sử dụng phương thức này cần được uỷ quyền bằng một hoặc nhiều phạm vi sau đây:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
getPageElementRange()
Trả về tập hợp PageElementRange của các phiên bản PageElement được chọn hoặc null nếu không có phiên bản PageElement nào được chọn.
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}`); }
Cầu thủ trả bóng
PageElementRange|null
Ủy quyền
Các tập lệnh sử dụng phương thức này cần được uỷ quyền bằng một hoặc nhiều phạm vi sau đây:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
getPageRange()
Trả về PageRange một tập hợp các thực thể Page trong dải băng được chọn hoặc null nếu lựa chọn không thuộc loại 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}`, ); }
Cầu thủ trả bóng
PageRange|null
Ủy quyền
Các tập lệnh sử dụng phương thức này cần được uỷ quyền bằng một hoặc nhiều phạm vi sau đây:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
getSelectionType()
Trả về 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()}`); }
Cầu thủ trả bóng
Ủy quyền
Các tập lệnh sử dụng phương thức này cần được uỷ quyền bằng một hoặc nhiều phạm vi sau đây:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
getTableCellRange()
Trả về tập hợp TableCellRange gồm các thực thể TableCell được chọn hoặc null nếu không có thực thể TableCell nào được chọn.
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}`); }
Cầu thủ trả bóng
TableCellRange|null
Ủy quyền
Các tập lệnh sử dụng phương thức này cần được uỷ quyền bằng một hoặc nhiều phạm vi sau đây:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
getTextRange()
Trả về TextRange đã chọn hoặc null nếu lựa chọn không thuộc loại SelectionType.TEXT.
TextRange đại diện cho hai trường hợp:
1. Phạm vi văn bản được chọn. Ví dụ: nếu một hình dạng có văn bản "Xin chào" và bạn chọn "Xin", thì dải ô được trả về sẽ có TextRange.getStartIndex() = 0 và TextRange.getEndIndex() = 2.
2. Vị trí con trỏ. Ví dụ: nếu một hình có văn bản "Hello" và con trỏ ở sau "H" ("H|ello"), thì dải ô được trả về sẽ có TextRange.getStartIndex() = 1 và 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()}`); }
Cầu thủ trả bóng
TextRange|null
Ủy quyền
Các tập lệnh sử dụng phương thức này cần được uỷ quyền bằng một hoặc nhiều phạm vi sau đây:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations