문서의 요소 범위입니다. 사용자의 선택은 다른 용도 중에서도 Range로 표시됩니다. 스크립트는 스크립트를 실행하는 사용자의 선택에만 액세스할 수 있으며, 스크립트가 문서에 바인딩된 경우에만 액세스할 수 있습니다.
// Bold all selected text.
const selection = DocumentApp.getActiveDocument().getSelection();
if (selection) {
const elements = selection.getRangeElements();
for (let i = 0; i < elements.length; i++) {
const element = elements[i];
// Only modify elements that can be edited as text; skip images and other
// non-text elements.
if (element.getElement().editAsText) {
const text = 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-03(UTC)"],[[["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()`."]]],[]]