การเลือกของผู้ใช้ในงานนำเสนอที่ใช้งานอยู่
const selection = SlidesApp.getActivePresentation().getSelection(); const currentPage = selection.getCurrentPage(); const selectionType = selection.getSelectionType();
เมธอด
| วิธีการ | ประเภทการแสดงผล | รายละเอียดแบบย่อ | 
|---|---|---|
| get | Page | แสดง 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
แสดง Page หรือ null ที่ใช้งานอยู่ในปัจจุบัน หากไม่มีหน้าเว็บที่ใช้งานอยู่
const selection = SlidesApp.getActivePresentation().getSelection(); const currentPage = selection.getCurrentPage(); if (currentPage != null) { Logger.log(`Selected current active page ID: ${currentPage.getObjectId()}`); }
รีเทิร์น
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
- 
https://www.googleapis.com/auth/presentations.currentonly
- 
https://www.googleapis.com/auth/presentations
get
แสดง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}`); }
รีเทิร์น
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
- 
https://www.googleapis.com/auth/presentations.currentonly
- 
https://www.googleapis.com/auth/presentations
get
แสดงผล 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}`, ); }
รีเทิร์น
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
- 
https://www.googleapis.com/auth/presentations.currentonly
- 
https://www.googleapis.com/auth/presentations
get
แสดงผล 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คอลเล็กชันอินสแตนซ์ 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}`); }
รีเทิร์น
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
- 
https://www.googleapis.com/auth/presentations.currentonly
- 
https://www.googleapis.com/auth/presentations
get
แสดงผล Text ที่เลือกไว้ หรือ null หากรายการที่เลือกไม่ใช่ประเภท Selection
Text แสดงถึง 2 สถานการณ์ ดังนี้
1. ช่วงที่เลือกข้อความ ตัวอย่างเช่น หากรูปร่างมีข้อความ "สวัสดี" และเลือก "เขา" Text = 0 และ Text = 2
2. ตำแหน่งเคอร์เซอร์ เช่น หากรูปร่างมีข้อความ "สวัสดี" อยู่ และเคอร์เซอร์อยู่หลัง "ฮ" นั่นคือ 
("ฮ|สวัสดี") ช่วงผลลัพธ์จะมี 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()}`); }
รีเทิร์น
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
- 
https://www.googleapis.com/auth/presentations.currentonly
- 
https://www.googleapis.com/auth/presentations