Class Selection

Lựa chọn

Lựa chọn của người dùng trong bản trình bày đang hoạt động.

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

Phương thức

Phương thứcKiểu dữ liệu trả vềMô tả ngắn
getCurrentPage()PageTrả về Page hoặc null đang hoạt động nếu không có trang nào đang hoạt động.
getPageElementRange()PageElementRangeTrả về tập hợp PageElementRange của các thực thể PageElement đã chọn hoặc null nếu chưa có thực thể PageElement nào được chọn.
getPageRange()PageRangeTrả về PageRange một tập hợp các thực thể Page trong flimstrip đã được chọn hoặc null nếu lựa chọn không thuộc loại SelectionType.PAGE.
getSelectionType()SelectionTypeTrả về SelectionType.
getTableCellRange()TableCellRangeTrả về tập hợp TableCellRange của các thực thể TableCell đã chọn hoặc null nếu chưa có thực thể TableCell nào được chọn.
getTextRange()TextRangeTrả về TextRange được chọn hoặc null nếu lựa chọn không thuộc loại SelectionType.TEXT.

Tài liệu chi tiết

getCurrentPage()

Trả về Page hoặc null đang hoạt động nếu không có trang nào đang hoạt động.

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

Cầu thủ trả bóng

Page

Ủy quyền

Tập lệnh sử dụng phương thức này cần được uỷ quyền với một hoặc nhiều phạm vi sau:

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

getPageElementRange()

Trả về tập hợp PageElementRange của các thực thể PageElement đã chọn hoặc null nếu chưa có thực thể PageElement nào được chọn.

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

Cầu thủ trả bóng

PageElementRange

Ủy quyền

Tập lệnh sử dụng phương thức này cần được uỷ quyền với một hoặc nhiều phạm vi sau:

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

getPageRange()

Trả về PageRange một tập hợp các thực thể Page trong flimstrip đã được chọn hoặc null nếu lựa chọn không thuộc loại 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);
}
}

Cầu thủ trả bóng

PageRange

Ủy quyền

Tập lệnh sử dụng phương thức này cần được uỷ quyền với một hoặc nhiều phạm vi sau:

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

getSelectionType()

Trả về 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());
}

Cầu thủ trả bóng

SelectionType

Ủy quyền

Tập lệnh sử dụng phương thức này cần được uỷ quyền với một hoặc nhiều phạm vi sau:

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

getTableCellRange()

Trả về tập hợp TableCellRange của các thực thể TableCell đã chọn hoặc null nếu chưa có thực thể TableCell nào được chọn.

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

Cầu thủ trả bóng

TableCellRange

Ủy quyền

Tập lệnh sử dụng phương thức này cần được uỷ quyền với một hoặc nhiều phạm vi sau:

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

getTextRange()

Trả về TextRange được chọn hoặc null nếu lựa chọn không thuộc loại SelectionType.TEXT.

TextRange đại diện cho 2 trường hợp:

1. Đã chọn dải văn bản. Ví dụ: nếu một hình dạng có văn bản "Hello" (Xin chào) và "He" được chọn, thì dải ô được trả về sẽ có TextRange.getStartIndex() = 0 và TextRange.getEndIndex() = 2.

2. Vị trí con trỏ. Ví dụ: nếu một hình dạng có văn bản "Hello" và con trỏ sau "H", ("H|ello"), thì dải ô được trả về có TextRange.getStartIndex() = 1 và 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());
}

Cầu thủ trả bóng

TextRange

Ủy quyền

Tập lệnh sử dụng phương thức này cần được uỷ quyền với một hoặc nhiều phạm vi sau:

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