Class HorizontalRule
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
자세한 문서
copy()
현재 요소의 분리된 전체 사본을 반환합니다.
요소에 있는 모든 하위 요소도 복사됩니다. 새 요소에 상위 요소가 없습니다.
리턴
HorizontalRule
: 새 사본입니다.
승인
이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getAttributes()
요소의 속성을 검색합니다.
결과는 유효한 각 요소 속성에 관한 속성을 포함하는 객체이며 각 속성 이름은 DocumentApp.Attribute
열거형의 항목에 해당합니다.
const doc = DocumentApp.getActiveDocument();
const documentTab = doc.getActiveTab().asDocumentTab();
const body = documentTab.getBody();
// Append a styled paragraph.
const par = body.appendParagraph('A bold, italicized paragraph.');
par.setBold(true);
par.setItalic(true);
// Retrieve the paragraph's attributes.
const atts = par.getAttributes();
// Log the paragraph attributes.
for (const att in atts) {
Logger.log(`${att}:${atts[att]}`);
}
리턴
Object
: 요소의 속성입니다.
승인
이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getNextSibling()
요소의 다음 동료 요소를 검색합니다.
다음 형제 요소는 동일한 상위 요소를 갖고 현재 요소 뒤에 나옵니다.
리턴
Element
: 다음 동료 요소입니다.
승인
이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getParent()
요소의 상위 요소를 가져옵니다.
상위 요소에 현재 요소가 포함되어 있습니다.
리턴
ContainerElement
: 상위 요소입니다.
승인
이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getPreviousSibling()
요소의 이전 동료 요소를 검색합니다.
이전 동료 요소는 상위 요소가 동일하며 현재 요소 앞에 있습니다.
리턴
Element
: 이전 동료 요소입니다.
승인
이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getType()
요소의 ElementType
를 검색합니다.
getType()
을 사용하여 특정 요소의 정확한 유형을 확인합니다.
const doc = DocumentApp.getActiveDocument();
const documentTab = doc.getActiveTab().asDocumentTab();
const body = documentTab.getBody();
// Obtain the first element in the active tab's body.
const firstChild = body.getChild(0);
// Use getType() to determine the element's type.
if (firstChild.getType() === DocumentApp.ElementType.PARAGRAPH) {
Logger.log('The first element is a paragraph.');
} else {
Logger.log('The first element is not a paragraph.');
}
리턴
ElementType
: 요소 유형입니다.
승인
이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
isAtDocumentEnd()
요소가 Document
의 끝에 있는지 확인합니다.
리턴
Boolean
: 요소가 탭의 끝에 있는지 여부입니다.
승인
이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
removeFromParent()
상위 요소에서 요소를 삭제합니다.
const doc = DocumentApp.getActiveDocument();
const documentTab = doc.getActiveTab().asDocumentTab();
const body = documentTab.getBody();
// Remove all images in the active tab's body.
const imgs = body.getImages();
for (let i = 0; i < imgs.length; i++) {
imgs[i].removeFromParent();
}
리턴
HorizontalRule
: 삭제된 요소입니다.
승인
이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setAttributes(attributes)
요소의 속성을 설정합니다.
지정된 attributes 매개변수는 각 속성 이름이 DocumentApp.Attribute
열거형의 항목이고 각 속성 값이 적용할 새 값인 객체여야 합니다.
const doc = DocumentApp.getActiveDocument();
const documentTab = doc.getActiveTab().asDocumentTab();
const body = documentTab.getBody();
// Define a custom paragraph style.
const style = {};
style[DocumentApp.Attribute.HORIZONTAL_ALIGNMENT] =
DocumentApp.HorizontalAlignment.RIGHT;
style[DocumentApp.Attribute.FONT_FAMILY] = 'Calibri';
style[DocumentApp.Attribute.FONT_SIZE] = 18;
style[DocumentApp.Attribute.BOLD] = true;
// Append a plain paragraph.
const par = body.appendParagraph('A paragraph with custom style.');
// Apply the custom style.
par.setAttributes(style);
매개변수
이름 | 유형 | 설명 |
attributes | Object | 요소의 속성 |
리턴
HorizontalRule
: 현재 요소입니다.
승인
이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-07-26(UTC)
[null,null,["최종 업데이트: 2025-07-26(UTC)"],[[["\u003cp\u003e\u003ccode\u003eHorizontalRule\u003c/code\u003e represents a horizontal line in a Google Doc and can be placed within a list item or paragraph but cannot contain other elements.\u003c/p\u003e\n"],["\u003cp\u003eIt provides methods for copying, manipulating attributes, navigating to sibling/parent elements, removing from the document, and checking its position.\u003c/p\u003e\n"],["\u003cp\u003eMethods like \u003ccode\u003ecopy()\u003c/code\u003e, \u003ccode\u003egetAttributes()\u003c/code\u003e, and \u003ccode\u003esetAttributes()\u003c/code\u003e allow for creating copies of the element and modifying its properties.\u003c/p\u003e\n"],["\u003cp\u003eYou can use \u003ccode\u003egetNextSibling()\u003c/code\u003e, \u003ccode\u003egetPreviousSibling()\u003c/code\u003e, and \u003ccode\u003egetParent()\u003c/code\u003e to traverse the document structure relative to the \u003ccode\u003eHorizontalRule\u003c/code\u003e element.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eremoveFromParent()\u003c/code\u003e enables removing the horizontal rule from its parent container, and \u003ccode\u003eisAtDocumentEnd()\u003c/code\u003e checks its location within the document.\u003c/p\u003e\n"]]],[],null,["# Class HorizontalRule\n\nHorizontalRule\n\nAn element representing an horizontal rule. A `Horizontal``Rule` can be contained within a\n[ListItem](/apps-script/reference/document/list-item) or [Paragraph](/apps-script/reference/document/paragraph), but cannot itself contain any other element. For more\ninformation on document structure, see the [guide to extending Google Docs](/apps-script/guides/docs#structure_of_a_document). \n\n### Methods\n\n| Method | Return type | Brief description |\n|-----------------------------------------------------|-----------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------|\n| [copy()](#copy()) | [HorizontalRule](#) | Returns a detached, deep copy of the current element. |\n| [getAttributes()](#getAttributes()) | `Object` | Retrieves the element's attributes. |\n| [getNextSibling()](#getNextSibling()) | [Element](/apps-script/reference/document/element) | Retrieves the element's next sibling element. |\n| [getParent()](#getParent()) | [ContainerElement](/apps-script/reference/document/container-element) | Retrieves the element's parent element. |\n| [getPreviousSibling()](#getPreviousSibling()) | [Element](/apps-script/reference/document/element) | Retrieves the element's previous sibling element. |\n| [getType()](#getType()) | [ElementType](/apps-script/reference/document/element-type) | Retrieves the element's [ElementType](/apps-script/reference/document/element-type). |\n| [isAtDocumentEnd()](#isAtDocumentEnd()) | `Boolean` | Determines whether the element is at the end of the [Document](/apps-script/reference/document/document). |\n| [removeFromParent()](#removeFromParent()) | [HorizontalRule](#) | Removes the element from its parent. |\n| [setAttributes(attributes)](#setAttributes(Object)) | [HorizontalRule](#) | Sets the element's attributes. |\n\nDetailed documentation\n----------------------\n\n### `copy()`\n\nReturns a detached, deep copy of the current element.\n\nAny child elements present in the element are also copied. The new element doesn't have a\nparent.\n\n#### Return\n\n\n[HorizontalRule](#) --- The new copy.\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/documents.currentonly`\n- `https://www.googleapis.com/auth/documents`\n\n*** ** * ** ***\n\n### `get``Attributes()`\n\nRetrieves the element's attributes.\n\nThe result is an object containing a property for each valid element attribute where each\nproperty name corresponds to an item in the `Document``App.Attribute` enumeration.\n\n```javascript\nconst doc = DocumentApp.getActiveDocument();\nconst documentTab = doc.getActiveTab().asDocumentTab();\nconst body = documentTab.getBody();\n\n// Append a styled paragraph.\nconst par = body.appendParagraph('A bold, italicized paragraph.');\npar.setBold(true);\npar.setItalic(true);\n\n// Retrieve the paragraph's attributes.\nconst atts = par.getAttributes();\n\n// Log the paragraph attributes.\nfor (const att in atts) {\n Logger.log(`${att}:${atts[att]}`);\n}\n```\n\n#### Return\n\n\n`Object` --- The element's attributes.\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/documents.currentonly`\n- `https://www.googleapis.com/auth/documents`\n\n*** ** * ** ***\n\n### `get``Next``Sibling()`\n\nRetrieves the element's next sibling element.\n\nThe next sibling has the same parent and follows the current element.\n\n#### Return\n\n\n[Element](/apps-script/reference/document/element) --- The next sibling element.\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/documents.currentonly`\n- `https://www.googleapis.com/auth/documents`\n\n*** ** * ** ***\n\n### `get``Parent()`\n\nRetrieves the element's parent element.\n\nThe parent element contains the current element.\n\n#### Return\n\n\n[ContainerElement](/apps-script/reference/document/container-element) --- The parent element.\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/documents.currentonly`\n- `https://www.googleapis.com/auth/documents`\n\n*** ** * ** ***\n\n### `get``Previous``Sibling()`\n\nRetrieves the element's previous sibling element.\n\nThe previous sibling has the same parent and precedes the current element.\n\n#### Return\n\n\n[Element](/apps-script/reference/document/element) --- The previous sibling element.\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/documents.currentonly`\n- `https://www.googleapis.com/auth/documents`\n\n*** ** * ** ***\n\n### `get``Type()`\n\nRetrieves the element's [ElementType](/apps-script/reference/document/element-type).\n\nUse `get``Type()` to determine the exact type of a given element.\n\n```javascript\nconst doc = DocumentApp.getActiveDocument();\nconst documentTab = doc.getActiveTab().asDocumentTab();\nconst body = documentTab.getBody();\n\n// Obtain the first element in the active tab's body.\n\nconst firstChild = body.getChild(0);\n\n// Use getType() to determine the element's type.\nif (firstChild.getType() === DocumentApp.ElementType.PARAGRAPH) {\n Logger.log('The first element is a paragraph.');\n} else {\n Logger.log('The first element is not a paragraph.');\n}\n```\n\n#### Return\n\n\n[ElementType](/apps-script/reference/document/element-type) --- The element type.\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/documents.currentonly`\n- `https://www.googleapis.com/auth/documents`\n\n*** ** * ** ***\n\n### `is``At``Document``End()`\n\nDetermines whether the element is at the end of the [Document](/apps-script/reference/document/document).\n\n#### Return\n\n\n`Boolean` --- Whether the element is at the end of the tab.\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/documents.currentonly`\n- `https://www.googleapis.com/auth/documents`\n\n*** ** * ** ***\n\n### `remove``From``Parent()`\n\nRemoves the element from its parent.\n\n```javascript\nconst doc = DocumentApp.getActiveDocument();\nconst documentTab = doc.getActiveTab().asDocumentTab();\nconst body = documentTab.getBody();\n\n// Remove all images in the active tab's body.\nconst imgs = body.getImages();\nfor (let i = 0; i \u003c imgs.length; i++) {\n imgs[i].removeFromParent();\n}\n```\n\n#### Return\n\n\n[HorizontalRule](#) --- The removed element.\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/documents.currentonly`\n- `https://www.googleapis.com/auth/documents`\n\n*** ** * ** ***\n\n### `set``Attributes(attributes)`\n\nSets the element's attributes.\n\nThe specified attributes parameter must be an object where each property name is an item in\nthe `Document``App.Attribute` enumeration and each property value is the new value to be\napplied.\n\n```javascript\nconst doc = DocumentApp.getActiveDocument();\nconst documentTab = doc.getActiveTab().asDocumentTab();\nconst body = documentTab.getBody();\n\n// Define a custom paragraph style.\nconst style = {};\nstyle[DocumentApp.Attribute.HORIZONTAL_ALIGNMENT] =\n DocumentApp.HorizontalAlignment.RIGHT;\nstyle[DocumentApp.Attribute.FONT_FAMILY] = 'Calibri';\nstyle[DocumentApp.Attribute.FONT_SIZE] = 18;\nstyle[DocumentApp.Attribute.BOLD] = true;\n\n// Append a plain paragraph.\nconst par = body.appendParagraph('A paragraph with custom style.');\n\n// Apply the custom style.\npar.setAttributes(style);\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|--------------|----------|---------------------------|\n| `attributes` | `Object` | The element's attributes. |\n\n#### Return\n\n\n[HorizontalRule](#) --- The current element.\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/documents.currentonly`\n- `https://www.googleapis.com/auth/documents`"]]