단락을 나타내는 요소. Paragraph
에는 Equation
, Footnote
, HorizontalRule
, InlineDrawing
, InlineImage
, PageBreak
, Text
요소가 포함될 수 있습니다. 문서 구조에 대한 자세한 내용은 Google 문서 확장 가이드를 참고하세요.
Paragraphs
에는 줄바꿈 문자가 포함될 수 없습니다. 줄바꿈 문자 ('\n')는 줄바꿈 문자 ('Crashlytics')로 변환됩니다.
var body = DocumentApp.getActiveDocument().getBody(); // Append a document header paragraph. var header = body.appendParagraph("A Document"); header.setHeading(DocumentApp.ParagraphHeading.HEADING1); // Append a section header paragraph. var section = body.appendParagraph("Section 1"); section.setHeading(DocumentApp.ParagraphHeading.HEADING2); // Append a regular paragraph. body.appendParagraph("This is a typical paragraph.");
방법
자세한 문서
addPositionedImage(image)
지정된 이미지 blob에서 새 PositionedImage
를 만들고 삽입합니다.
// Opens the Docs file by its ID. If you created your script from within // a Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('abc123456'); // Gets the document body. const body = doc.getBody(); // Gets the first paragraph from the body. const paragraph = body.getParagraphs()[0]; // Fetches the specified image URL. const image = UrlFetchApp.fetch('https://fonts.gstatic.com/s/i/productlogos/apps_script/v10/web-24dp/logo_apps_script_color_1x_web_24dp.png'); // Adds the image to the document, anchored to the first paragraph. paragraph.addPositionedImage(image);
매개변수
이름 | 유형 | 설명 |
---|---|---|
image | BlobSource | 이미지 데이터입니다. |
리턴
PositionedImage
- 새로 배치된 이미지입니다.
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
appendHorizontalRule()
새 HorizontalRule
를 만들고 추가합니다.
// Opens the Docs file by its ID. If you created your script from within // a Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('abc123456'); // Gets the document body. const body = doc.getBody(); // Gets the first paragraph from the body. const paragraph = body.getParagraphs()[0]; // Adds a horizontal line under the first paragraph. paragraph.appendHorizontalRule();
리턴
HorizontalRule
- 새 가로 규칙입니다.
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
appendInlineImage(image)
지정된 이미지 blob에서 새 InlineImage
를 만들고 추가합니다.
// Opens the Docs file by its ID. If you created your script from within // a Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('abc123456'); // Gets the document body. const body = doc.getBody(); // Gets the first paragraph from the body. const paragraph = body.getParagraphs()[0]; // Fetches the image from the specified image URL. const image = UrlFetchApp .fetch('https://fonts.gstatic.com/s/i/productlogos/apps_script/v10/web-96dp/logo_apps_script_color_1x_web_96dp.png'); // Adds the image to the first paragraph. paragraph.appendInlineImage(image);
매개변수
이름 | 유형 | 설명 |
---|---|---|
image | BlobSource | 이미지 데이터입니다. |
리턴
InlineImage
- 추가된 이미지입니다.
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
appendInlineImage(image)
지정된 InlineImage
를 추가합니다.
// Opens the Docs file by its ID. If you created your script from within // a Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('abc123456'); // Gets the document body. const body = doc.getBody(); // Gets the first paragraph from the body. const paragraph = body.getParagraphs()[0]; // Makes a copy of the first image in the body. const image = body.getImages()[0].copy();; // Adds the image to the first paragraph. paragraph.appendInlineImage(image);
매개변수
이름 | 유형 | 설명 |
---|---|---|
image | InlineImage | 이미지 데이터입니다. |
리턴
InlineImage
- 추가된 이미지입니다.
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
appendPageBreak()
새 PageBreak
를 만들고 추가합니다.
참고: PageBreaks
는 TableCells
내에 포함되지 않을 수 있습니다.
현재 요소가 테이블 셀에 포함되어 있으면 예외가 발생합니다.
// Opens the Docs file by its ID. If you created your script from within // a Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('abc123456'); // Gets the document body. const body = doc.getBody(); // Gets the first paragraph from the body. const paragraph = body.getParagraphs()[0]; // Adds a page break after the first paragraph. paragraph.appendPageBreak();
리턴
PageBreak
— 새 페이지 나누기 요소입니다.
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
appendPageBreak(pageBreak)
지정된 PageBreak
를 추가합니다.
참고: PageBreaks
는 TableCells
내에 포함될 수 없습니다.
현재 요소가 테이블 셀에 있으면 스크립트에서 예외가 발생합니다.
// Opens the Docs file by its ID. If you created your script from within // a Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('abc123456'); // Gets the document body. const body = doc.getBody(); // Gets the first paragraph from the body. const paragraph = body.getParagraphs()[0]; // Adds a page break after the first paragraph. const pageBreak = paragraph.appendPageBreak(); // Makes a copy of the page break. const newPageBreak = pageBreak.copy(); // Adds the copied page break to the paragraph. paragraph.appendPageBreak(newPageBreak);
매개변수
이름 | 유형 | 설명 |
---|---|---|
pageBreak | PageBreak | 추가할 페이지 나누기입니다. |
리턴
PageBreak
: 추가된 페이지 나누기 요소입니다.
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
appendText(text)
지정된 콘텐츠로 새 Text
요소를 만들고 추가합니다.
// Opens the Docs file by its ID. If you created your script from within // a Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('abc123456'); // Gets the document body. const body = doc.getBody(); // Gets the first paragraph from the body. const paragraph = body.getParagraphs()[0]; // Adds a string to the paragraph. paragraph.appendText('This is a new sentence.');
매개변수
이름 | 유형 | 설명 |
---|---|---|
text | String | 텍스트 콘텐츠입니다. |
리턴
Text
- 새 텍스트 요소입니다.
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
appendText(text)
지정된 Text
요소를 추가합니다.
// Opens the Docs file by its ID. If you created your script from within // a Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('abc123456'); // Gets the document body. const body = doc.getBody(); // Gets the text from the first paragraph in the body. const paragraph1 = body.getParagraphs()[0]; const text = paragraph1.getText(); // Gets the third paragraph in the body. const paragraph3 = body.getParagraphs()[2]; // Adds the text from the first paragraph to the third paragraph. paragraph3.appendText(text);
매개변수
이름 | 유형 | 설명 |
---|---|---|
text | Text | 추가할 텍스트 요소입니다. |
리턴
Text
- 추가된 텍스트 요소입니다.
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
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);
리턴
Text
: 현재 요소의 텍스트 버전입니다.
findElement(elementType)
요소의 콘텐츠에서 지정된 유형의 하위 요소를 검색합니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
elementType | ElementType | 검색할 요소 유형 |
리턴
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 | 검색할 검색결과 |
리턴
RangeElement
: 검색 요소의 다음 위치를 나타내는 검색결과
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
findText(searchPattern)
정규 표현식을 사용하여 지정된 텍스트 패턴의 요소 콘텐츠를 검색합니다.
자바스크립트 정규 표현식 기능의 하위 집합(예: 캡처 그룹 및 모드 수정자)은 완전히 지원되지 않습니다.
제공된 정규 표현식 패턴은 현재 요소에 포함된 각 텍스트 블록과 독립적으로 비교됩니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
searchPattern | String | 검색할 패턴 |
리턴
RangeElement
— 검색 텍스트의 위치를 나타내는 검색결과 또는 일치하는 항목이 없는 경우 null
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
findText(searchPattern, from)
지정된 검색결과부터 요소의 콘텐츠에서 지정된 텍스트 패턴을 검색합니다.
자바스크립트 정규 표현식 기능의 하위 집합(예: 캡처 그룹 및 모드 수정자)은 완전히 지원되지 않습니다.
제공된 정규 표현식 패턴은 현재 요소에 포함된 각 텍스트 블록과 독립적으로 비교됩니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
searchPattern | String | 검색할 패턴 |
from | RangeElement | 검색할 검색결과 |
리턴
RangeElement
— 검색 텍스트의 다음 위치를 나타내는 검색결과 또는 일치하는 항목이 없는 경우 null
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getAlignment()
HorizontalAlignment
를 검색합니다.
// Opens the Docs file by its ID. If you created your script from within // a Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('abc123456'); // Gets the document body. const body = doc.getBody(); // Gets the first paragraph from the body. const paragraph = body.getParagraphs()[0]; // Sets the horizontal alignment to left for the first paragraph. paragraph.setAlignment(DocumentApp.HorizontalAlignment.LEFT); // Gets the horizontal alignment of the first paragraph and logs it to the console. console.log(paragraph.getAlignment().toString());
리턴
HorizontalAlignment
- 정렬입니다.
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
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]); }
리턴
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 | 검색할 하위 요소의 색인 |
리턴
Element
- 지정된 색인의 하위 요소
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getChildIndex(child)
getHeading()
ParagraphHeading
를 검색합니다.
// Opens the Docs file by its ID. If you created your script from within // a Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('abc123456'); // Gets the document body. const body = doc.getBody(); // Adds a paragraph to the body. const paragraph = body.appendParagraph('Title heading'); // Sets the paragraph heading style to 'Title.' paragraph.setHeading(DocumentApp.ParagraphHeading.TITLE); // Gets the heading style and logs it to the console. console.log(paragraph.getHeading().toString());
리턴
ParagraphHeading
- 제목
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getIndentEnd()
끝 들여쓰기를 포인트 단위로 검색합니다.
리턴
Number
- 들여쓰기 간격(포인트)
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getIndentFirstLine()
첫 번째 줄 들여쓰기를 가져옵니다.
리턴
Number
— 첫 번째 줄 들여쓰기(포인트)
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getIndentStart()
시작 들여쓰기를 검색합니다.
리턴
Number
— 시작 들여쓰기
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getLineSpacing()
줄 간격을 포인트 단위로 검색합니다.
리턴
Number
— 줄 간격(포인트)
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getLinkUrl()
링크 URL을 검색합니다.
리턴
String
— 링크 URL 또는 요소에 이 속성의 값이 여러 개 포함된 경우 null
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getNextSibling()
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.");
리턴
Integer
— 하위 요소 수
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
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
getPositionedImage(id)
이미지 ID로 PositionedImage
를 가져옵니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
id | String | 이미지 ID |
리턴
PositionedImage
— 배치된 이미지
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getPositionedImages()
단락에 고정된 모든 PositionedImage
객체를 가져옵니다.
리턴
PositionedImage[]
- 배치된 이미지 목록
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getPreviousSibling()
getSpacingAfter()
요소 뒤의 간격을 검색합니다.
리턴
Number
— 요소 뒤의 간격(포인트)입니다.
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getSpacingBefore()
요소 앞의 간격을 포인트 단위로 검색합니다.
리턴
Number
— 요소 앞의 간격(포인트)
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getText()
요소의 내용을 텍스트 문자열로 검색합니다.
리턴
String
— 텍스트 콘텐츠로 된 요소의 콘텐츠
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getTextAlignment()
텍스트 정렬을 가져옵니다. 사용 가능한 정렬 유형은 DocumentApp.TextAlignment.NORMAL
, DocumentApp.TextAlignment.SUBSCRIPT
, DocumentApp.TextAlignment.SUPERSCRIPT
입니다.
리턴
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.'); }
리턴
ElementType
- 요소 유형입니다.
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
insertHorizontalRule(childIndex)
지정된 색인에 HorizontalRule
을 만들고 삽입합니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
childIndex | Integer | 요소를 삽입할 색인 |
리턴
HorizontalRule
— 새 가로 규칙 요소
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
insertInlineImage(childIndex, image)
지정된 이미지 blob에서 지정된 색인에 새 InlineImage
를 만들어 삽입합니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
childIndex | Integer | 요소를 삽입할 색인 |
image | BlobSource | 이미지 데이터 |
리턴
InlineImage
- 삽입된 인라인 이미지 요소
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
insertInlineImage(childIndex, image)
지정된 색인에 지정된 InlineImage
를 삽입합니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
childIndex | Integer | 요소를 삽입할 색인 |
image | InlineImage | 이미지 데이터 |
리턴
InlineImage
- 삽입된 인라인 이미지 요소
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
insertPageBreak(childIndex)
지정된 색인에 새 PageBreak
를 만들어 삽입합니다.
참고: PageBreaks
는 TableCells
내에 포함되지 않을 수 있습니다.
현재 요소가 테이블 셀에 포함되어 있으면 예외가 발생합니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
childIndex | Integer | 요소를 삽입할 색인 |
리턴
PageBreak
— 새 페이지 나누기 요소
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
insertPageBreak(childIndex, pageBreak)
지정된 색인에 지정된 PageBreak
를 삽입합니다.
참고: PageBreaks
는 TableCells
내에 포함되지 않을 수 있습니다.
현재 요소가 테이블 셀에 포함되어 있으면 예외가 발생합니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
childIndex | Integer | 요소를 삽입할 색인 |
pageBreak | PageBreak | 삽입할 페이지 길이 |
리턴
PageBreak
— 삽입된 페이지 나누기 요소
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
insertText(childIndex, text)
insertText(childIndex, text)
isAtDocumentEnd()
isLeftToRight()
왼쪽에서 오른쪽 설정을 검색합니다.
리턴
Boolean
: 왼쪽에서 오른쪽으로 설정
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
merge()
요소를 동일한 유형의 이전 동위 요소와 병합합니다.
동일한 ElementType
의 요소만 병합할 수 있습니다. 현재 요소에 포함된 모든 하위 요소는 이전 동위 요소로 이동합니다.
현재 요소가 문서에서 삭제됩니다.
var body = DocumentApp.getActiveDocument().getBody(); // Example 1: Merge paragraphs // Append two paragraphs to the document. 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();
리턴
Paragraph
- 병합된 요소.
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
removeChild(child)
removeFromParent()
상위 요소에서 요소를 삭제합니다.
var body = DocumentApp.getActiveDocument().getBody(); // Remove all images in the document body. var imgs = body.getImages(); for (var i = 0; i < imgs.length; i++) { imgs[i].removeFromParent(); }
리턴
Paragraph
- 삭제된 요소입니다.
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
removePositionedImage(id)
이미지 ID로 PositionedImage
를 삭제합니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
id | String | 이미지 ID |
리턴
Boolean
: 지정된 이미지의 삭제 여부입니다.
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
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 | 대체 텍스트로 사용할 텍스트 |
리턴
Element
— 현재 요소
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setAlignment(alignment)
HorizontalAlignment
를 설정합니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
alignment | HorizontalAlignment | 가로 정렬 |
리턴
Paragraph
— 현재 요소
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
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 | 요소의 속성입니다. |
리턴
Paragraph
- 현재 요소입니다.
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setHeading(heading)
ParagraphHeading
를 설정합니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
heading | ParagraphHeading | 제목 |
리턴
Paragraph
— 현재 요소
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setIndentEnd(indentEnd)
setIndentFirstLine(indentFirstLine)
setIndentStart(indentStart)
setLeftToRight(leftToRight)
setLineSpacing(multiplier)
setLinkUrl(url)
setSpacingAfter(spacingAfter)
setSpacingBefore(spacingBefore)
setText(text)
단락의 콘텐츠를 텍스트로 설정합니다.
참고: 기존 콘텐츠는 삭제됩니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
text | String | 새 텍스트 콘텐츠 |
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
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 | 적용할 텍스트 정렬 유형 |
리턴
Paragraph
— 현재 요소
승인
이 방법을 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents