Interface Element

요소

일반 요소입니다. 콘텐츠 Document개 요소로 표현됩니다. 예를 들어 ListItem, Paragraph, Table는 다음과 같습니다. 요소를 사용하고 getType()와 같은 Element에서 정의한 모든 메서드를 상속합니다.

클래스 구현

이름간략한 설명
BodyGoogle Docs 문서의 탭 콘텐츠입니다.
ContainerElement다른 요소를 포함할 수 있는 일반 요소입니다.
Date형식이 지정된 날짜를 나타내는 요소입니다.
Equation수식을 나타내는 요소입니다.
EquationFunction수학 Equation에서 함수를 나타내는 요소입니다.
EquationFunctionArgumentSeparator수학 Equation에서 함수 구분자를 나타내는 요소입니다.
EquationSymbol수학 Equation에서 기호를 나타내는 요소입니다.
FooterSection바닥글 섹션을 나타내는 요소입니다.
Footnote각주를 나타내는 요소입니다.
FootnoteSection각주 섹션을 나타내는 요소입니다.
HeaderSection헤더 섹션을 나타내는 요소입니다.
HorizontalRule가로 규칙을 나타내는 요소입니다.
InlineDrawing삽입된 그림을 나타내는 요소입니다.
InlineImage삽입된 이미지를 나타내는 요소입니다.
ListItem목록 항목을 나타내는 요소입니다.
PageBreak페이지 나누기를 나타내는 요소입니다.
Paragraph단락을 나타내는 요소입니다.
Person사람에 대한 링크를 나타내는 요소입니다.
RichLinkDrive 파일 또는 YouTube 동영상과 같이 Google 리소스의 링크를 나타내는 요소입니다.
Table테이블을 나타내는 요소입니다.
TableCell테이블 셀을 나타내는 요소입니다.
TableOfContents목차가 포함된 요소입니다.
TableRow표의 행을 나타내는 요소입니다.
Text서식 있는 텍스트 영역을 나타내는 요소입니다.
UnsupportedElement알 수 없거나 스크립트의 영향을 받을 수 없는 영역을 나타내는 요소입니다. 예를 들면 페이지 번호

메서드

메서드반환 유형간략한 설명
asBody()Body현재 요소를 Body로 반환합니다.
asDate()Date현재 요소를 Date로 반환합니다.
asEquation()Equation현재 요소를 Equation로 반환합니다.
asEquationFunction()EquationFunction현재 요소를 EquationFunction로 반환합니다.
asEquationFunctionArgumentSeparator()EquationFunctionArgumentSeparator현재 요소를 EquationFunctionArgumentSeparator로 반환합니다.
asEquationSymbol()EquationSymbol현재 요소를 EquationSymbol로 반환합니다.
asFooterSection()FooterSection현재 요소를 FooterSection로 반환합니다.
asFootnote()Footnote현재 요소를 Footnote로 반환합니다.
asFootnoteSection()FootnoteSection현재 요소를 FootnoteSection로 반환합니다.
asHeaderSection()HeaderSection현재 요소를 HeaderSection로 반환합니다.
asHorizontalRule()HorizontalRule현재 요소를 HorizontalRule로 반환합니다.
asInlineDrawing()InlineDrawing현재 요소를 InlineDrawing로 반환합니다.
asInlineImage()InlineImage현재 요소를 InlineImage로 반환합니다.
asListItem()ListItem현재 요소를 ListItem로 반환합니다.
asPageBreak()PageBreak현재 요소를 PageBreak로 반환합니다.
asParagraph()Paragraph현재 요소를 Paragraph로 반환합니다.
asPerson()Person현재 요소를 Person로 반환합니다.
asRichLink()RichLink현재 요소를 RichLink로 반환합니다(예: Google Sheets 파일 링크).
asTable()Table현재 요소를 Table로 반환합니다.
asTableCell()TableCell현재 요소를 TableCell로 반환합니다.
asTableOfContents()TableOfContents현재 요소를 TableOfContents로 반환합니다.
asTableRow()TableRow현재 요소를 TableRow로 반환합니다.
asText()Text현재 요소를 Text로 반환합니다.
copy()Element현재 요소의 분리된 전체 사본을 반환합니다.
getAttributes()Object요소의 속성을 검색합니다.
getNextSibling()Element요소의 다음 동위 요소를 검색합니다.
getParent()ContainerElement요소의 상위 요소를 검색합니다.
getPreviousSibling()Element요소의 이전 동위 요소를 검색합니다.
getType()ElementType요소의 ElementType를 검색합니다.
isAtDocumentEnd()Boolean요소가 Document 끝에 있는지 확인합니다.
merge()Element요소를 동일한 유형의 앞의 동위 요소와 병합합니다.
removeFromParent()Element상위 항목에서 요소를 삭제합니다.
setAttributes(attributes)Element요소의 속성을 설정합니다.

자세한 문서

asBody()

현재 요소를 Body로 반환합니다.

이 메서드를 사용하면 특정 요소가 특정 있습니다.

리턴

Body - 현재 요소입니다.

승인

이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상으로 승인이 필요합니다.

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asDate()

현재 요소를 Date로 반환합니다.

요소가 Date임을 알고 있으면 이 메서드를 사용하여 요소의 유형을 Date로 설정합니다. 이렇게 하면 Apps Script 편집기의 자동 완성을 통해 사용할 수 있는 메서드가 표시됩니다. Date로 교체합니다.

리턴

Date - 유형이 Date로 설정된 현재 요소입니다.

승인

이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상으로 승인이 필요합니다.

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asEquation()

현재 요소를 Equation로 반환합니다.

이 메서드를 사용하면 특정 요소가 특정 있습니다.

리턴

Equation - 현재 요소입니다.

승인

이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상으로 승인이 필요합니다.

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asEquationFunction()

현재 요소를 EquationFunction로 반환합니다.

이 메서드를 사용하면 특정 요소가 특정 있습니다.

리턴

EquationFunction - 현재 요소입니다.

승인

이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상으로 승인이 필요합니다.

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asEquationFunctionArgumentSeparator()

현재 요소를 EquationFunctionArgumentSeparator로 반환합니다.

이 메서드를 사용하면 특정 요소가 특정 있습니다.

리턴

EquationFunctionArgumentSeparator - 현재 요소입니다.

승인

이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상으로 승인이 필요합니다.

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asEquationSymbol()

현재 요소를 EquationSymbol로 반환합니다.

이 메서드를 사용하면 특정 요소가 특정 있습니다.

리턴

EquationSymbol - 현재 요소입니다.

승인

이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상으로 승인이 필요합니다.

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asFooterSection()

현재 요소를 FooterSection로 반환합니다.

이 메서드를 사용하면 특정 요소가 특정 있습니다.

리턴

FooterSection - 현재 요소입니다.

승인

이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상으로 승인이 필요합니다.

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asFootnote()

현재 요소를 Footnote로 반환합니다.

이 메서드를 사용하면 특정 요소가 특정 있습니다.

리턴

Footnote - 현재 요소입니다.

승인

이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상으로 승인이 필요합니다.

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asFootnoteSection()

현재 요소를 FootnoteSection로 반환합니다.

이 메서드를 사용하면 특정 요소가 특정 있습니다.

리턴

FootnoteSection - 현재 요소입니다.

승인

이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상으로 승인이 필요합니다.

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asHeaderSection()

현재 요소를 HeaderSection로 반환합니다.

이 메서드를 사용하면 특정 요소가 특정 있습니다.

리턴

HeaderSection - 현재 요소입니다.

승인

이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상으로 승인이 필요합니다.

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asHorizontalRule()

현재 요소를 HorizontalRule로 반환합니다.

이 메서드를 사용하면 특정 요소가 특정 있습니다.

리턴

HorizontalRule - 현재 요소입니다.

승인

이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상으로 승인이 필요합니다.

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asInlineDrawing()

현재 요소를 InlineDrawing로 반환합니다.

이 메서드를 사용하면 특정 요소가 특정 있습니다.

리턴

InlineDrawing - 현재 요소입니다.

승인

이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상으로 승인이 필요합니다.

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asInlineImage()

현재 요소를 InlineImage로 반환합니다.

이 메서드를 사용하면 특정 요소가 특정 있습니다.

리턴

InlineImage - 현재 요소입니다.

승인

이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상으로 승인이 필요합니다.

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asListItem()

현재 요소를 ListItem로 반환합니다.

이 메서드를 사용하면 특정 요소가 특정 있습니다.

리턴

ListItem - 현재 요소입니다.

승인

이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상으로 승인이 필요합니다.

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asPageBreak()

현재 요소를 PageBreak로 반환합니다.

이 메서드를 사용하면 특정 요소가 특정 있습니다.

리턴

PageBreak - 현재 요소입니다.

승인

이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상으로 승인이 필요합니다.

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asParagraph()

현재 요소를 Paragraph로 반환합니다.

이 메서드를 사용하면 특정 요소가 특정 있습니다.

리턴

Paragraph - 현재 요소입니다.

승인

이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상으로 승인이 필요합니다.

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asPerson()

현재 요소를 Person로 반환합니다.

요소가 Person임을 알고 있으면 이 메서드를 사용하여 요소의 유형을 사람으로 설정합니다. 이렇게 하면 Apps Script 편집기의 자동 완성을 통해 사람 요소입니다.

리턴

Person - 유형이 Person로 설정된 현재 요소입니다.

승인

이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상으로 승인이 필요합니다.

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

현재 요소를 RichLink로 반환합니다(예: Google Sheets 파일 링크).

요소가 RichLink임을 알고 있으면 이 메서드를 사용하여 요소의 유형을 RichLink로 설정합니다. 이렇게 하면 Apps Script 편집기의 자동 완성을 통해 RichLink와 함께 사용합니다.

리턴

RichLink - 유형이 RichLink로 설정된 현재 요소입니다.

승인

이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상으로 승인이 필요합니다.

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asTable()

현재 요소를 Table로 반환합니다.

이 메서드를 사용하면 특정 요소가 특정 있습니다.

리턴

Table - 현재 요소입니다.

승인

이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상으로 승인이 필요합니다.

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asTableCell()

현재 요소를 TableCell로 반환합니다.

이 메서드를 사용하면 특정 요소가 특정 있습니다.

리턴

TableCell - 현재 요소입니다.

승인

이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상으로 승인이 필요합니다.

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asTableOfContents()

현재 요소를 TableOfContents로 반환합니다.

이 메서드를 사용하면 특정 요소가 특정 있습니다.

리턴

TableOfContents - 현재 요소입니다.

승인

이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상으로 승인이 필요합니다.

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asTableRow()

현재 요소를 TableRow로 반환합니다.

이 메서드를 사용하면 특정 요소가 특정 있습니다.

리턴

TableRow - 현재 요소입니다.

승인

이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상으로 승인이 필요합니다.

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asText()

현재 요소를 Text로 반환합니다.

이 메서드를 사용하면 특정 요소가 특정 있습니다.

리턴

Text - 현재 요소입니다.

승인

이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상으로 승인이 필요합니다.

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

copy()

현재 요소의 분리된 전체 사본을 반환합니다.

요소에 있는 모든 하위 요소도 복사됩니다. 새 요소에는 있습니다.

리턴

Element - 새 사본입니다.

승인

이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상으로 승인이 필요합니다.

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

getAttributes()

요소의 속성을 검색합니다.

결과는 유효한 각 요소 속성에 대한 속성을 포함하는 객체이며, 여기서 각 요소는 속성 이름은 DocumentApp.Attribute 열거형의 항목에 해당합니다.

var doc = DocumentApp.getActiveDocument();
var documentTab = doc.getActiveTab().asDocumentTab();
var body = documentTab.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]);
}

리턴

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()를 사용합니다.

var doc = DocumentApp.getActiveDocument();
var documentTab = doc.getActiveTab().asDocumentTab();
var body = documentTab.getBody();

// Obtain the first element in the active tab's 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.');
}

리턴

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

merge()

요소를 동일한 유형의 앞의 동위 요소와 병합합니다.

동일한 ElementType의 요소만 병합할 수 있습니다. 현재 요소가 이전 동위 요소로 이동합니다.

현재 요소가 문서에서 삭제됩니다.

var doc = DocumentApp.getActiveDocument();
var documentTab = doc.getActiveTab().asDocumentTab();
var body = documentTab.getBody();

// Example 1: Merge paragraphs
// Append two paragraphs to the document's active tab.
var par1 = body.appendParagraph('Paragraph 1.');
var par2 = body.appendParagraph('Paragraph 2.');
// Merge the newly added paragraphs into a single paragraph.
par2.merge();

// Example 2: Merge table cells
// Create a two-dimensional array containing the table's cell contents.
var cells = [
['Row 1, Cell 1', 'Row 1, Cell 2'],
['Row 2, Cell 1', 'Row 2, Cell 2']
];
// Build a table from the array.
var table = body.appendTable(cells);
// Get the first row in the table.
 var row = table.getRow(0);
// Get the two cells in this row.
var cell1 = row.getCell(0);
var cell2 = row.getCell(1);
// Merge the current cell into its preceding sibling element.
var merged = cell2.merge();

리턴

Element - 병합된 요소입니다.

승인

이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상으로 승인이 필요합니다.

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

removeFromParent()

상위 항목에서 요소를 삭제합니다.

var doc = DocumentApp.getActiveDocument();
var documentTab = doc.getActiveTab().asDocumentTab()
var body = documentTab.getBody();

// Remove all images in the active tab's body.
var imgs = body.getImages();
for (var i = 0; i < imgs.length; i++) {
  imgs[i].removeFromParent();
}

리턴

Element - 삭제된 요소입니다.

승인

이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상으로 승인이 필요합니다.

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

setAttributes(attributes)

요소의 속성을 설정합니다.

지정된 속성 매개변수는 각 속성 이름이 항목인 객체여야 합니다. DocumentApp.Attribute 열거형이며 각 속성 값은 새 값입니다. 적용됩니다.

var doc = DocumentApp.getActiveDocument();
var documentTab = doc.getActiveTab().asDocumentTab();
var body = documentTab.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);

매개변수

이름유형설명
attributesObject요소의 속성입니다.

리턴

Element - 현재 요소입니다.

승인

이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상으로 승인이 필요합니다.

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents