Class Selection

การเลือก

สิ่งที่ผู้ใช้เลือกในงานนำเสนอที่ใช้งานอยู่

const selection = SlidesApp.getActivePresentation().getSelection();
const currentPage = selection.getCurrentPage();
const selectionType = selection.getSelectionType();

เมธอด

วิธีการประเภทการแสดงผลรายละเอียดแบบย่อ
getCurrentPage()Page|nullแสดง Page หรือ null ที่ใช้งานอยู่ในปัจจุบัน หากไม่มีหน้าที่ใช้งานอยู่
getPageElementRange()PageElementRange|nullแสดงPageElementRangeคอลเล็กชันของอินสแตนซ์ PageElement ที่เลือก หรือ null หากไม่ได้เลือกอินสแตนซ์ PageElement
getPageRange()PageRange|nullแสดงผลPageRangeชุดอินสแตนซ์ของ Page ในแถบภาพยนตร์ที่ เลือกไว้ หรือ null หากการเลือกไม่ใช่ประเภท SelectionType.PAGE
getSelectionType()SelectionTypeแสดง SelectionType
getTableCellRange()TableCellRange|nullแสดงผลTableCellRangeคอลเล็กชันของTableCellอินสแตนซ์ที่เลือก หรือ null หากไม่มีTableCellอินสแตนซ์ที่เลือก
getTextRange()TextRange|nullแสดงผล TextRange ที่เลือก หรือ null หากการเลือกไม่ได้เป็นประเภท SelectionType.TEXT

เอกสารโดยละเอียด

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()}`);
}

รีเทิร์น

SelectionType

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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