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 | Loại dữ liệu trả về | Mô tả ngắn |
---|---|---|
get | Page | Trả về Page hoặc null đ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 thực thể Page đã được chọn hoặc null nếu không có thực thể 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 phim đượ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 của các thực thể Table đã 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
đ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
Ủy quyền
Các tập lệnh sử dụng phương thức này yêu cầu được uỷ quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
getPageElementRange()
Trả về tập hợp Page
của các thực thể Page
đã được chọn hoặc null
nếu không có thực thể Page
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
Ủy quyền
Các tập lệnh sử dụng phương thức này yêu cầu được uỷ quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
getPageRange()
Trả về Page
một tập hợp các thực thể Page
trong dải phim được chọn hoặc null
nếu lựa chọn không thuộc loại Selection
.
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
Ủy quyền
Các tập lệnh sử dụng phương thức này yêu cầu được uỷ quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
getSelectionType()
Trả về Selection
.
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 yêu cầu được uỷ quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
getTableCellRange()
Trả về tập hợp Table
của các thực thể Table
đã chọn hoặc null
nếu không có thực thể Table
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
Ủy quyền
Các tập lệnh sử dụng phương thức này yêu cầu được uỷ quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
getTextRange()
Trả về Text
đã chọn hoặc null
nếu lựa chọn không thuộc loại Selection
.
Text
đại diện cho hai trường hợp:
1. Phạm vi văn bản đã chọn. Ví dụ: nếu một hình dạng có văn bản "Hello" (Xin chào) và "He" (Anh) được chọn, thì phạm vi được trả về sẽ có Text
= 0 và Text
= 2.
2. Vị trí con trỏ. Ví dụ: nếu một hình dạng có văn bản "Hello" và con trỏ nằm sau "H",
("H|ello"), thì dải ô được trả về sẽ có Text
= 1 và Text
= 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
Ủy quyền
Các tập lệnh sử dụng phương thức này yêu cầu được uỷ quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations