Class Selection

การเลือก

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

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

วิธีการ

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

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

getCurrentPage()

แสดงผล Page หรือ null ที่ใช้งานอยู่ในปัจจุบัน หากไม่มีหน้าที่ใช้งานอยู่

var selection = SlidesApp.getActivePresentation().getSelection();
var currentPage = selection.getCurrentPage();
if (currentPage != null) {
  Logger.log('Selected current active page ID: ' + currentPage.getObjectId());
}

รีเทิร์น

Page

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

สคริปต์ที่ใช้วิธีการนี้ต้องได้รับสิทธิ์จากขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

getPageElementRange()

แสดงผลคอลเล็กชัน PageElementRange ของอินสแตนซ์ PageElement ที่เลือกไว้ หรือ null หากไม่ได้เลือกอินสแตนซ์ PageElement

var selection = SlidesApp.getActivePresentation().getSelection();
var selectionType = selection.getSelectionType();
if (selectionType == SlidesApp.SelectionType.PAGE_ELEMENT) {
  var currentPage = selection.getCurrentPage();
  var pageElements = selection.getPageElementRange().getPageElements();
  Logger.log('Number of page elements selected: ' + pageElements.length);
}

รีเทิร์น

PageElementRange

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

สคริปต์ที่ใช้วิธีการนี้ต้องได้รับสิทธิ์จากขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

getPageRange()

แสดงผล PageRange คอลเล็กชันของอินสแตนซ์ Page ใน Flimstrip ที่เลือกไว้ หรือ null หากสิ่งที่เลือกไม่ใช่ประเภท SelectionType.PAGE

var selection = SlidesApp.getActivePresentation().getSelection();
var selectionType = selection.getSelectionType();
if (selectionType == SlidesApp.SelectionType.PAGE) {
  var pageRange = selection.getPageRange();
  Logger.log('Number of pages in the flimstrip selected: ' + pageRange.getPages().length);
}
}

รีเทิร์น

PageRange

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

สคริปต์ที่ใช้วิธีการนี้ต้องได้รับสิทธิ์จากขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

getSelectionType()

แสดงผล SelectionType

var selection = SlidesApp.getActivePresentation().getSelection();
var selectionType = selection.getSelectionType();
if (selectionType == SlidesApp.SelectionType.CURRENT_PAGE) {
  var 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

var selection = SlidesApp.getActivePresentation().getSelection();
var selectionType = selection.getSelectionType();
if (selectionType == SlidesApp.SelectionType.TABLE_CELL) {
  var currentPage = selection.getCurrentPage();
  var tableCells = selection.getTableCellRange().getTableCells();
  var table = tableCells[0].getParentTable();
  Logger.log('Number of table cells selected: ' + tableCells.length);
}

รีเทิร์น

TableCellRange

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

สคริปต์ที่ใช้วิธีการนี้ต้องได้รับสิทธิ์จากขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

getTextRange()

แสดงผล TextRange ที่เลือก หรือ null หากสิ่งที่เลือกไม่ใช่ประเภท SelectionType.TEXT

TextRange หมายถึง 2 สถานการณ์ต่อไปนี้

1. เลือกช่วงของข้อความแล้ว เช่น หากรูปร่างมีข้อความ "สวัสดี" และเลือก "เขา" ช่วงที่แสดงผลจะมี TextRange.getStartIndex() = 0 และ TextRange.getEndIndex() = 2

2. ตำแหน่งเคอร์เซอร์ เช่น หากรูปร่างมีข้อความ "สวัสดี" และเคอร์เซอร์อยู่หลัง "H", ("H|ello") ช่วงที่แสดงผลจะมี TextRange.getStartIndex() = 1 และ TextRange.getEndIndex() = 1

var selection = SlidesApp.getActivePresentation().getSelection();
var selectionType = selection.getSelectionType();
if (selectionType == SlidesApp.SelectionType.TEXT) {
  var currentPage = selection.getCurrentPage();
  var pageElement = selection.getPageElementRange().getPageElements()[0];
  var textRange = selection.getTextRange();
  Logger.log('Text selected: ' + textRange.asString());
}

รีเทิร์น

TextRange

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

สคริปต์ที่ใช้วิธีการนี้ต้องได้รับสิทธิ์จากขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations