สิ่งที่ผู้ใช้เลือกในงานนำเสนอที่ใช้งานอยู่
const selection = SlidesApp.getActivePresentation().getSelection(); const currentPage = selection.getCurrentPage(); const selectionType = selection.getSelectionType();
เมธอด
| วิธีการ | ประเภทการแสดงผล | รายละเอียดแบบย่อ |
|---|---|---|
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
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
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
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
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
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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()}`); }
รีเทิร์น
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
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
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
getTextRange()
แสดงผล TextRange ที่เลือก หรือ null หากการเลือกไม่ได้เป็นประเภท
SelectionType.TEXT
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