문서 본문을 나타내는 요소입니다. Body
에는 ListItem
, Paragraph
, Table
, TableOfContents
요소가 포함될 수 있습니다. 문서 구조에 대한 자세한 내용은 Google 문서 확장 가이드를 참조하세요.
Body
에는 일반적으로 HeaderSection
, FooterSection
및 FootnoteSection
요소를 제외한 전체 문서 콘텐츠가 포함됩니다.
var doc = DocumentApp.getActiveDocument(); var body = doc.getBody(); // Append a paragraph and a page break to the document body section directly. body.appendParagraph("A paragraph."); body.appendPageBreak();
메서드
자세한 문서
appendHorizontalRule()
새 HorizontalRule
를 만들고 추가합니다.
HorizontalRule
는 새 Paragraph
에 포함됩니다.
Return
HorizontalRule
: 새 가로 규칙
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상을 사용하여 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
appendImage(image)
지정된 이미지 blob에서 새 InlineImage
를 만들고 추가합니다.
이미지가 새 Paragraph
에 포함됩니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
image | BlobSource | 이미지 데이터 |
Return
InlineImage
— 추가된 이미지
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상을 사용하여 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
appendImage(image)
지정된 InlineImage
를 추가합니다.
InlineImage
는 새 Paragraph
에 포함됩니다.
기존 InlineImage
의 사본을 추가할 때 이 버전의 appendImage
을 사용합니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
image | InlineImage | 이미지 데이터 |
Return
InlineImage
— 추가된 이미지
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상을 사용하여 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
appendListItem(listItem)
appendListItem(text)
appendPageBreak()
appendPageBreak(pageBreak)
지정된 PageBreak
를 추가합니다.
PageBreak
는 새 Paragraph
에 포함됩니다.
기존 PageBreak
의 사본을 추가할 때 이 버전의 appendPageBreak
을 사용합니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
pageBreak | PageBreak | 추가할 페이지 나누기 |
Return
PageBreak
— 추가된 페이지 나누기
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상을 사용하여 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
appendParagraph(paragraph)
appendParagraph(text)
appendTable()
appendTable(cells)
지정된 각 문자열 값에 TableCell
를 포함하는 새 Table
을 추가합니다.
또한 이 메서드는 Google Docs 문서가 표로 끝날 수 없으므로 표 다음에 빈 단락을 추가합니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
cells | String[][] | 새 테이블에 추가할 표 셀의 텍스트 콘텐츠 |
Return
Table
— 추가된 테이블
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상을 사용하여 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
appendTable(table)
지정된 Table
를 추가합니다.
기존 Table
의 사본을 추가할 때 이 버전의 appendTable
을 사용합니다.
또한 이 메서드는 Google Docs 문서가 표로 끝날 수 없으므로 표 다음에 빈 단락을 추가합니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
table | Table | 추가할 테이블 |
Return
Table
— 추가된 테이블
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상을 사용하여 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
clear()
copy()
editAsText()
수정할 현재 요소의 Text
버전을 가져옵니다.
요소 콘텐츠를 리치 텍스트로 조작하려면 editAsText
를 사용합니다. editAsText
모드는 텍스트가 아닌 요소 (예: InlineImage
및 HorizontalRule
)를 무시합니다.
삭제된 텍스트 범위 내에 완전히 포함된 하위 요소가 요소에서 삭제됩니다.
var body = DocumentApp.getActiveDocument().getBody(); // Insert two paragraphs separated by a paragraph containing an // horizontal rule. body.insertParagraph(0, "An editAsText sample."); body.insertHorizontalRule(0); body.insertParagraph(0, "An example."); // Delete " sample.\n\n An" removing the horizontal rule in the process. body.editAsText().deleteText(14, 25);
Return
Text
: 현재 요소의 텍스트 버전
findElement(elementType)
요소의 콘텐츠에서 지정된 유형의 하위 요소를 검색합니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
elementType | ElementType | 검색할 요소 유형 |
Return
RangeElement
— 검색 요소의 위치를 나타내는 검색결과
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상을 사용하여 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
findElement(elementType, from)
지정된 RangeElement
에서 시작하여 지정된 유형의 하위 요소를 요소의 내용에서 검색합니다.
// Get the body section of the active document. var body = DocumentApp.getActiveDocument().getBody(); // Define the search parameters. var searchType = DocumentApp.ElementType.PARAGRAPH; var searchHeading = DocumentApp.ParagraphHeading.HEADING1; var searchResult = null; // Search until the paragraph is found. while (searchResult = body.findElement(searchType, searchResult)) { var par = searchResult.getElement().asParagraph(); if (par.getHeading() == searchHeading) { // Found one, update and stop. par.setText('This is the first header.'); return; } }
매개변수
이름 | 유형 | 설명 |
---|---|---|
elementType | ElementType | 검색할 요소 유형 |
from | RangeElement | 검색할 검색결과 |
Return
RangeElement
— 검색 요소의 다음 위치를 나타내는 검색결과
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상을 사용하여 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
findText(searchPattern)
정규 표현식을 사용하여 지정된 텍스트 패턴의 요소 콘텐츠를 검색합니다.
자바스크립트 정규 표현식 기능의 하위 집합(예: 캡처 그룹 및 모드 수정자)은 완전히 지원되지 않습니다.
제공된 정규 표현식 패턴은 현재 요소에 포함된 각 텍스트 블록과 독립적으로 일치합니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
searchPattern | String | 검색할 패턴 |
Return
RangeElement
— 검색 텍스트의 위치를 나타내는 검색결과 또는 일치하는 항목이 없는 경우 null
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상을 사용하여 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
findText(searchPattern, from)
지정된 검색결과부터 요소의 텍스트 콘텐츠를 지정된 텍스트 패턴으로 검색합니다.
자바스크립트 정규 표현식 기능의 하위 집합(예: 캡처 그룹 및 모드 수정자)은 완전히 지원되지 않습니다.
제공된 정규 표현식 패턴은 현재 요소에 포함된 각 텍스트 블록과 독립적으로 일치합니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
searchPattern | String | 검색할 패턴 |
from | RangeElement | 검색할 검색결과 |
Return
RangeElement
— 검색 텍스트의 다음 위치를 나타내는 검색결과 또는 일치하는 항목이 없는 경우 null
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상을 사용하여 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getAttributes()
요소의 속성을 검색합니다.
결과는 유효한 각 요소 속성에 대한 속성을 포함하는 객체입니다. 여기서 각 속성 이름은 DocumentApp.Attribute
열거형의 항목에 해당합니다.
var body = DocumentApp.getActiveDocument().getBody(); // Append a styled paragraph. var par = body.appendParagraph('A bold, italicized paragraph.'); par.setBold(true); par.setItalic(true); // Retrieve the paragraph's attributes. var atts = par.getAttributes(); // Log the paragraph attributes. for (var att in atts) { Logger.log(att + ":" + atts[att]); }
Return
Object
— 요소의 속성입니다.
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상을 사용하여 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getChild(childIndex)
지정된 하위 색인에서 하위 요소를 검색합니다.
// Get the body section of the active document. var body = DocumentApp.getActiveDocument().getBody(); // Obtain the first element in the document. var firstChild = body.getChild(0); // If it's a paragraph, set its contents. if (firstChild.getType() == DocumentApp.ElementType.PARAGRAPH) { firstChild.asParagraph().setText("This is the first paragraph."); }
매개변수
이름 | 유형 | 설명 |
---|---|---|
childIndex | Integer | 검색할 하위 요소의 색인 |
Return
Element
: 지정된 색인의 하위 요소
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상을 사용하여 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getChildIndex(child)
getHeadingAttributes(paragraphHeading)
제공된 ParagraphHeading
의 속성 집합을 검색합니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
paragraphHeading | ParagraphHeading | 속성을 가져올 제목 |
Return
Object
: 속성 및 현재 값의 매핑
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상을 사용하여 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getImages()
섹션에 포함된 모든 InlineImages
를 검색합니다.
Return
InlineImage[]
— 섹션 이미지
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상을 사용하여 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getListItems()
섹션에 포함된 모든 ListItems
를 검색합니다.
Return
ListItem[]
— 섹션 목록 항목
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상을 사용하여 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getMarginBottom()
하단 여백을 포인트 단위로 검색합니다.
Return
Number
- 하단 여백(포인트)
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상을 사용하여 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getMarginLeft()
왼쪽 여백을 포인트 단위로 검색합니다.
Return
Number
— 왼쪽 여백(포인트)
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상을 사용하여 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getMarginRight()
오른쪽 여백을 검색합니다.
Return
Number
— 오른쪽 여백(포인트)
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상을 사용하여 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getMarginTop()
상단 여백을 검색합니다.
Return
Number
— 포인트의 상단 여백
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상을 사용하여 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getNumChildren()
하위 요소의 수를 검색합니다.
// Get the body section of the active document. var body = DocumentApp.getActiveDocument().getBody(); // Log the number of elements in the document. Logger.log("There are " + body.getNumChildren() + " elements in the document body.");
Return
Integer
— 하위 요소 수
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상을 사용하여 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getPageHeight()
페이지 높이를 가져옵니다.
Return
Number
— 페이지 높이(포인트)
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상을 사용하여 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getPageWidth()
페이지 너비를 검색합니다(점).
Return
Number
— 페이지 너비(포인트)
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상을 사용하여 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getParagraphs()
섹션에 포함된 모든 Paragraphs
(ListItems
포함)을 검색합니다.
Return
Paragraph[]
— 섹션 단락
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상을 사용하여 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getParent()
요소의 상위 요소를 검색합니다.
상위 요소에 현재 요소가 포함되어 있습니다.
Return
ContainerElement
: 상위 요소입니다.
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상을 사용하여 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getTables()
getText()
요소의 내용을 텍스트 문자열로 검색합니다.
Return
String
: 요소의 콘텐츠(텍스트 문자열)입니다.
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상을 사용하여 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getTextAlignment()
텍스트 정렬을 가져옵니다. 사용 가능한 정렬 유형은 DocumentApp.TextAlignment.NORMAL
, DocumentApp.TextAlignment.SUBSCRIPT
, DocumentApp.TextAlignment.SUPERSCRIPT
입니다.
Return
TextAlignment
: 텍스트 정렬 유형 또는 텍스트에 여러 유형의 텍스트 정렬이 포함되어 있거나 텍스트 정렬이 설정되지 않은 경우 null
입니다.
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상을 사용하여 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getType()
요소의 ElementType
를 검색합니다.
getType()
를 사용하여 특정 요소의 정확한 유형을 확인합니다.
var body = DocumentApp.getActiveDocument().getBody(); // Obtain the first element in the document body. var 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.'); }
Return
ElementType
: 요소 유형입니다.
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상을 사용하여 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
insertHorizontalRule(childIndex)
지정된 색인에서 새 HorizontalRule
를 만들고 삽입합니다.
HorizontalRule
는 새 Paragraph
에 포함됩니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
childIndex | Integer | 엘리먼트를 삽입할 색인 |
Return
HorizontalRule
: 새 가로 규칙
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상을 사용하여 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
insertImage(childIndex, image)
지정된 이미지 blob에서 지정된 색인에 InlineImage
를 만들고 삽입합니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
childIndex | Integer | 엘리먼트를 삽입할 색인 |
image | BlobSource | 이미지 데이터 |
Return
InlineImage
— 삽입된 인라인 이미지
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상을 사용하여 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
insertImage(childIndex, image)
지정된 색인에 지정된 InlineImage
를 삽입합니다.
이미지가 새 Paragraph
에 포함됩니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
childIndex | Integer | 엘리먼트를 삽입할 색인 |
image | InlineImage | 삽입할 이미지 |
Return
InlineImage
— 삽입된 인라인 이미지
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상을 사용하여 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
insertListItem(childIndex, listItem)
insertListItem(childIndex, text)
insertPageBreak(childIndex)
insertPageBreak(childIndex, pageBreak)
지정된 색인에 지정된 PageBreak
를 삽입합니다.
PageBreak
는 새 Paragraph
에 포함됩니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
childIndex | Integer | 엘리먼트를 삽입할 색인 |
pageBreak | PageBreak | 삽입할 기간 |
Return
PageBreak
— 삽입된 페이지 나누기
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상을 사용하여 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
insertParagraph(childIndex, paragraph)
insertParagraph(childIndex, text)
insertTable(childIndex)
insertTable(childIndex, cells)
insertTable(childIndex, table)
removeChild(child)
replaceText(searchPattern, replacement)
정규 표현식을 사용하여 지정된 텍스트 패턴의 모든 항목을 지정된 대체 문자열로 바꿉니다.
검색 패턴은 자바스크립트 정규 표현식 객체가 아닌 문자열로 전달됩니다. 따라서 이 패턴에서는 백슬래시를 이스케이프 처리해야 합니다.
이 메서드는 지원되는 구문을 제한하는 Google의 RE2 정규 표현식 라이브러리를 사용합니다.
제공된 정규 표현식 패턴은 현재 요소에 포함된 각 텍스트 블록과 독립적으로 일치합니다.
var body = DocumentApp.getActiveDocument().getBody(); // Clear the text surrounding "Apps Script", with or without text. body.replaceText("^.*Apps ?Script.*$", "Apps Script");
매개변수
이름 | 유형 | 설명 |
---|---|---|
searchPattern | String | 검색할 정규 표현식 패턴 |
replacement | String | 대체용으로 사용할 텍스트 |
Return
Element
: 현재 요소
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상을 사용하여 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setAttributes(attributes)
요소의 속성을 설정합니다.
지정된 속성 매개변수는 각 속성 이름이 DocumentApp.Attribute
열거형 항목이며 각 속성 값이 적용할 새 값인 객체여야 합니다.
var body = DocumentApp.getActiveDocument().getBody(); // Define a custom paragraph style. var 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. var par = body.appendParagraph('A paragraph with custom style.'); // Apply the custom style. par.setAttributes(style);
매개변수
이름 | 유형 | 설명 |
---|---|---|
attributes | Object | 요소의 속성입니다. |
Return
Body
: 현재 요소입니다.
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상을 사용하여 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setHeadingAttributes(paragraphHeading, attributes)
제공된 ParagraphHeading
의 속성을 설정합니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
paragraphHeading | ParagraphHeading | 속성이 설정될 제목 |
attributes | Object | 설정할 속성과 값의 매핑 |
Return
Body
: 현재 요소
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상을 사용하여 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setMarginBottom(marginBottom)
setMarginLeft(marginLeft)
setMarginRight(marginRight)
setMarginTop(marginTop)
setPageHeight(pageHeight)
setPageWidth(pageWidth)
setText(text)
setTextAlignment(textAlignment)
텍스트 정렬을 설정합니다. 사용 가능한 정렬 유형은 DocumentApp.TextAlignment.NORMAL
, DocumentApp.TextAlignment.SUBSCRIPT
, DocumentApp.TextAlignment.SUPERSCRIPT
입니다.
// Make the entire first paragraph be superscript. var text = DocumentApp.getActiveDocument().getBody().getParagraphs()[0].editAsText(); text.setTextAlignment(DocumentApp.TextAlignment.SUPERSCRIPT);
매개변수
이름 | 유형 | 설명 |
---|---|---|
textAlignment | TextAlignment | 적용할 텍스트 정렬 유형 |
Return
Body
: 현재 요소
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상을 사용하여 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents