方法
| 方法 | 傳回類型 | 簡短說明 |
|---|---|---|
get | Element | 取得與這個 Range 對應的 Element。 |
get | Integer | 取得範圍元素中部分範圍的結尾位置。 |
get | Integer | 取得範圍元素中部分範圍的起始位置。 |
is | Boolean | 判斷這個範圍元素是否涵蓋整個元素,或只涵蓋元素字元的部分選取範圍。 |
內容詳盡的說明文件
getElement()
取得與這個 RangeElement 對應的 Element。
const rangeElement = DocumentApp.getActiveDocument().getSelection().getRangeElements()[0]; // Log debug information about a range element. Logger.log(`Element type: ${rangeElement.getElement().getType()}`); if (rangeElement.isPartial()) { Logger.log(`The character range begins at ${rangeElement.getStartOffset()}`); Logger.log( `The character range ends at ${rangeElement.getEndOffsetInclusive()}`, ); } else { Logger.log('The entire range element is included.'); }
回攻員
Element:對應這個 RangeElement 的元素
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getEndOffsetInclusive()
取得範圍元素中部分範圍的結尾位置。如果元素是 Text 元素且 isPartial() 會傳回 true,則位移是範圍中最後一個字元之前的字元數 (也就是範圍中最後一個字元的索引);在任何其他情況下,這個方法會傳回 -1。
回攻員
Integer:如果是 Text 元素,則為範圍中最後一個字元之前的字元數;如果是其他元素,則為
-1
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getStartOffset()
取得範圍元素中部分範圍的起始位置。如果元素是 Text 元素,且 isPartial() 會傳回 true,則位移是範圍開頭前的字元數 (也就是範圍中第一個字元的索引);在任何其他情況下,這個方法都會傳回 -1。
回攻員
Integer:如果是 Text 元素,則為範圍開頭前的字元數;如果是其他元素,則為 -1
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
isPartial()
判斷這個範圍元素是否涵蓋整個元素,或只涵蓋元素字元的部分選取範圍。部分範圍元素範圍的開頭和結尾分別可使用 getStartOffset() 和 getEndOffsetInclusive() 判斷。
回攻員
Boolean - true (如果元素部分包含);false (如果元素未包含)
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents