文件中的元素範圍。使用者的選項會以 Range 和其他用途表示。指令碼只能存取執行指令碼的使用者所選取的項目,且只有在指令碼繫結至文件時才能存取。
// Bold all selected text.constselection=DocumentApp.getActiveDocument().getSelection();if(selection){constelements=selection.getRangeElements();for(leti=0;i < elements.length;i++){constelement=elements[i];// Only modify elements that can be edited as text; skip images and other// non-text elements.if(element.getElement().editAsText){consttext=element.getElement().editAsText();// Bold the selected part of the element, or the full element if it's// completely selected.if(element.isPartial()){text.setBold(element.getStartOffset(),element.getEndOffsetInclusive(),true,);}else{text.setBold(true);}}}}
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2024-12-22 (世界標準時間)。"],[[["A `Range` represents a range of elements in a Google Doc, often used to represent the user's selection."],["Scripts can only access the selection of the user who is running them within the bound document."],["The `getRangeElements()` method retrieves all elements within the range, including partially selected text elements."],["The `getSelectedElements()` method is deprecated and has been replaced by `getRangeElements()`."]]],[]]