สิ่งที่ผู้ใช้เลือกในงานนำเสนอที่ใช้งานอยู่
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 |
เอกสารโดยละเอียด
get Current Page()
แสดง 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
get Page Element Range()
แสดงPageคอลเล็กชันของอินสแตนซ์ Page ที่เลือก หรือ null หากไม่ได้เลือกอินสแตนซ์ Page
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}`); }
รีเทิร์น
Page
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
get Page Range()
แสดงผลPageชุดอินสแตนซ์ของ Page ในแถบภาพยนตร์ที่
เลือกไว้ หรือ null หากการเลือกไม่ใช่ประเภท 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}`, ); }
รีเทิร์น
Page
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
get Selection Type()
แสดง 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()}`); }
รีเทิร์น
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
get Table Cell Range()
แสดงผลTableคอลเล็กชันของTableอินสแตนซ์ที่เลือก
หรือ null หากไม่มีTableอินสแตนซ์ที่เลือก
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}`); }
รีเทิร์น
Table
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
get Text Range()
แสดงผล Text ที่เลือก หรือ null หากการเลือกไม่ได้เป็นประเภท
Selection
Text แสดงถึง 2 สถานการณ์ต่อไปนี้
1. เลือกช่วงข้อความ เช่น หากรูปร่างมีข้อความ "Hello" และเลือก "He"
ช่วงที่แสดงผลจะมี Text = 0 และ Text =
2
2. ตำแหน่งเคอร์เซอร์ เช่น หากรูปร่างมีข้อความ "Hello" และเคอร์เซอร์อยู่หลัง "H" (
("H|ello")) ช่วงที่แสดงผลจะมี Text = 1 และ 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()}`); }
รีเทิร์น
Text
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations