文档中的元素范围。用户的选择会以 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"]],["最后更新时间 (UTC):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()`."]]],[]]