Class Text

텍스트

서식 있는 텍스트 영역을 나타내는 요소입니다. Document의 모든 텍스트는 Text 요소 내에 포함됩니다. Text 요소는 Equation, EquationFunction 내에 포함될 수 있습니다. ListItem 또는 Paragraph이지만 자체에 다른 요소를 포함할 수 없습니다. 자세한 내용은 자세한 내용은 Google Docs 확장 가이드를 참조하세요.

// Gets the body contents of the active tab.
var body = DocumentApp.getActiveDocument().getActiveTab().asDocumentTab().getBody();

// Use editAsText to obtain a single text element containing
// all the characters in the tab.
var text = body.editAsText();

// Insert text at the beginning of the tab.
text.insertText(0, 'Inserted text.\n');

// Insert text at the end of the tab.
text.appendText('\nAppended text.');

// Make the first half of the tab blue.
text.setForegroundColor(0, text.getText().length / 2, '#00FFFF');

메서드

메서드반환 유형간략한 설명
appendText(text)Text이 텍스트 영역의 끝에 지정된 텍스트를 추가합니다.
copy()Text현재 요소의 분리된 전체 사본을 반환합니다.
deleteText(startOffset, endOffsetInclusive)Text텍스트 범위를 삭제합니다.
editAsText()Text수정을 위해 현재 요소의 Text 버전을 가져옵니다.
findText(searchPattern)RangeElement정규 표현식을 사용하여 요소의 콘텐츠에서 지정된 텍스트 패턴을 검색합니다.
findText(searchPattern, from)RangeElement요소의 콘텐츠에서 지정된 텍스트 패턴(지정된 텍스트부터 시작)을 검색합니다. 표시됩니다.
getAttributes()Object요소의 속성을 검색합니다.
getAttributes(offset)Object지정된 문자 오프셋에서 속성을 검색합니다.
getBackgroundColor()String배경색 설정을 검색합니다.
getBackgroundColor(offset)String지정된 문자 오프셋의 배경 색상을 검색합니다.
getFontFamily()String글꼴 모음 설정을 검색합니다.
getFontFamily(offset)String지정된 문자 오프셋에서 글꼴 모음을 검색합니다.
getFontSize()Number글꼴 크기 설정을 검색합니다.
getFontSize(offset)Number지정된 문자 오프셋에서 글꼴 크기를 검색합니다.
getForegroundColor()String전경 색상 설정을 검색합니다.
getForegroundColor(offset)String지정된 문자 오프셋의 전경 색상을 검색합니다.
getLinkUrl()String링크 URL을 검색합니다.
getLinkUrl(offset)String지정된 문자 오프셋에 있는 링크 URL을 검색합니다.
getNextSibling()Element요소의 다음 동위 요소를 검색합니다.
getParent()ContainerElement요소의 상위 요소를 검색합니다.
getPreviousSibling()Element요소의 이전 동위 요소를 검색합니다.
getText()String요소의 콘텐츠를 텍스트 문자열로 검색합니다.
getTextAlignment()TextAlignment텍스트 정렬을 가져옵니다.
getTextAlignment(offset)TextAlignment단일 문자의 텍스트 정렬을 가져옵니다.
getTextAttributeIndices()Integer[]고유한 텍스트 형식의 시작 부분에 해당하는 텍스트 색인 집합을 검색합니다. 실행할 수도 있습니다
getType()ElementType요소의 ElementType를 검색합니다.
insertText(offset, text)Text지정된 문자 오프셋에 지정된 텍스트를 삽입합니다.
isAtDocumentEnd()Boolean요소가 Document 끝에 있는지 확인합니다.
isBold()Boolean굵게 설정을 검색합니다.
isBold(offset)Boolean지정된 문자 오프셋에서 굵게 설정을 검색합니다.
isItalic()Boolean기울임꼴 설정을 검색합니다.
isItalic(offset)Boolean지정된 문자 오프셋에서 기울임꼴 설정을 검색합니다.
isStrikethrough()Boolean취소선 설정을 검색합니다.
isStrikethrough(offset)Boolean지정된 문자 오프셋의 취소선 설정을 검색합니다.
isUnderline()Boolean밑줄 설정을 검색합니다.
isUnderline(offset)Boolean지정된 문자 오프셋에서 밑줄 설정을 검색합니다.
merge()Text요소를 동일한 유형의 앞의 동위 요소와 병합합니다.
removeFromParent()Text상위 항목에서 요소를 삭제합니다.
replaceText(searchPattern, replacement)Element정규식을 사용하여 지정된 텍스트 패턴과 일치하는 모든 항목을 지정된 대체 문자열로 바꿉니다. 식을 사용할 수 있습니다.
setAttributes(startOffset, endOffsetInclusive, attributes)Text지정된 속성을 지정된 문자 범위에 적용합니다.
setAttributes(attributes)Text요소의 속성을 설정합니다.
setBackgroundColor(startOffset, endOffsetInclusive, color)Text지정된 문자 범위의 배경 색상을 설정합니다.
setBackgroundColor(color)Text배경 색상을 설정합니다.
setBold(bold)Text굵게 설정을 설정합니다.
setBold(startOffset, endOffsetInclusive, bold)Text지정된 문자 범위에 굵게 설정을 설정합니다.
setFontFamily(startOffset, endOffsetInclusive, fontFamilyName)Text지정된 문자 범위의 글꼴 모음을 설정합니다.
setFontFamily(fontFamilyName)Text글꼴 모음을 설정합니다.
setFontSize(startOffset, endOffsetInclusive, size)Text지정된 문자 범위의 글꼴 크기를 설정합니다.
setFontSize(size)Text글꼴 크기를 설정합니다.
setForegroundColor(startOffset, endOffsetInclusive, color)Text지정된 문자 범위의 전경 색상을 설정합니다.
setForegroundColor(color)Text전경 색상을 설정합니다.
setItalic(italic)Text기울임꼴 설정을 설정합니다.
setItalic(startOffset, endOffsetInclusive, italic)Text지정된 문자 범위에 대해 기울임꼴 설정을 설정합니다.
setLinkUrl(startOffset, endOffsetInclusive, url)Text지정된 문자 범위에 대한 링크 URL을 설정합니다.
setLinkUrl(url)Text링크 URL을 설정합니다.
setStrikethrough(strikethrough)Text취소선 설정을 설정합니다.
setStrikethrough(startOffset, endOffsetInclusive, strikethrough)Text지정된 문자 범위에 취소선 설정을 설정합니다.
setText(text)Text텍스트 콘텐츠를 설정합니다.
setTextAlignment(startOffset, endOffsetInclusive, textAlignment)Text지정된 문자 범위의 텍스트 정렬을 설정합니다.
setTextAlignment(textAlignment)Text텍스트 정렬을 설정합니다.
setUnderline(underline)Text밑줄 설정을 설정합니다.
setUnderline(startOffset, endOffsetInclusive, underline)Text지정된 문자 범위에 밑줄 설정을 설정합니다.

자세한 문서

appendText(text)

이 텍스트 영역의 끝에 지정된 텍스트를 추가합니다.

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Adds the text, 'Sample body text,' to the end of the tab body.
const text = body.editAsText().appendText('Sample body text');

매개변수

이름유형설명
textString추가할 텍스트입니다.

리턴

Text - 현재 요소입니다.

승인

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

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

copy()

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

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

리턴

Text - 새 사본입니다.

승인

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

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

deleteText(startOffset, endOffsetInclusive)

텍스트 범위를 삭제합니다.

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Deletes the first 10 characters in the body.
 const text = body.editAsText().deleteText(0, 9);

매개변수

이름유형설명
startOffsetInteger삭제할 첫 번째 문자의 문자 오프셋입니다.
endOffsetInclusiveInteger삭제할 마지막 문자의 문자 오프셋입니다.

리턴

Text - 현재 요소입니다.

승인

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

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

editAsText()

수정을 위해 현재 요소의 Text 버전을 가져옵니다.

요소 콘텐츠를 서식 있는 텍스트로 조작하는 데 editAsText를 사용합니다. editAsText 모드는 텍스트가 아닌 요소 (예: InlineImageHorizontalRule)를 무시합니다.

삭제된 텍스트 범위 내에 완전히 포함된 하위 요소는 요소에서 삭제됩니다.

var body = DocumentApp.getActiveDocument().getActiveTab().asDocumentTab().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: 현재 요소의 텍스트 버전


findText(searchPattern)

정규 표현식을 사용하여 요소의 콘텐츠에서 지정된 텍스트 패턴을 검색합니다.

JavaScript 정규 표현식 기능의 하위 집합은 완전히 지원되지 않습니다. 예를 들면 다음과 같습니다. 그룹 및 모드 수정자를 캡처합니다.

제공된 정규 표현식 패턴이 각 텍스트 블록과 독립적으로 일치됩니다. .

매개변수

이름유형설명
searchPatternString검색할 패턴

리턴

RangeElement — 검색 텍스트의 위치를 나타내는 검색 결과, 또는 없는 경우 null 일치

승인

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

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

findText(searchPattern, from)

요소의 콘텐츠에서 지정된 텍스트 패턴(지정된 텍스트부터 시작)을 검색합니다. 표시됩니다.

JavaScript 정규 표현식 기능의 하위 집합은 완전히 지원되지 않습니다. 예를 들면 다음과 같습니다. 그룹 및 모드 수정자를 캡처합니다.

제공된 정규 표현식 패턴이 각 텍스트 블록과 독립적으로 일치됩니다. .

매개변수

이름유형설명
searchPatternString검색할 패턴
fromRangeElement검색할 검색결과

리턴

RangeElement: 검색 텍스트의 다음 위치를 나타내는 검색 결과, 또는 없는 경우 null입니다. 일치

승인

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

  • 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

getAttributes(offset)

지정된 문자 오프셋에서 속성을 검색합니다.

그 결과 유효한 텍스트 속성 각각에 대한 속성을 포함하는 객체가 생성됩니다. 속성 이름은 DocumentApp.Attribute 열거형의 항목에 해당합니다.

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Declares style attributes.
const style = {}
style[DocumentApp.Attribute.BOLD] = true;
style[DocumentApp.Attribute.ITALIC] = true;
style[DocumentApp.Attribute.FONT_SIZE] = 29;

// Sets the style attributes to the tab's body.
const text = body.editAsText();
text.setAttributes(style);

// Gets the style attributes applied to the eleventh character in the
// body and logs them to the console.
const attributes = text.getAttributes(10);
console.log(attributes);

매개변수

이름유형설명
offsetInteger문자 오프셋입니다.

리턴

Object - 요소의 속성입니다.

승인

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

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

getBackgroundColor()

배경색 설정을 검색합니다.

리턴

String: CSS 표기법 (예: '#ffffff')으로 형식이 지정된 배경 색상 또는 null 요소에 이 속성의 값이 여러 개 포함된 경우

승인

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

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

getBackgroundColor(offset)

지정된 문자 오프셋의 배경 색상을 검색합니다.

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Sets the background color of the first 3 characters in the body.
const text = body.editAsText().setBackgroundColor(0, 2, '#FFC0CB');

// Gets the background color of the first character in the body.
const backgroundColor = text.getBackgroundColor(0);

// Logs the background color to the console.
console.log(backgroundColor);

매개변수

이름유형설명
offsetInteger문자 오프셋입니다.

리턴

String - CSS 표기법 (예: '#ffffff')으로 형식이 지정된 배경 색상입니다.

승인

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

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

getFontFamily()

글꼴 모음 설정을 검색합니다. 이름은 Docs의 글꼴 메뉴 또는 Google Fonts에 있는 모든 글꼴로 지정할 수 있으며 대소문자를 구분합니다. getFontFamily()setFontFamily(fontFamilyName) 메서드가 이제 글꼴에 문자열 이름을 사용하는 대신 FontFamily enum 이 열거형은 이전 스크립트와의 호환성을 위해 계속 사용할 수 있습니다.

리턴

String: 글꼴 모음 또는 요소에 이 속성의 값이 여러 개 포함된 경우 null

승인

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

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

getFontFamily(offset)

지정된 문자 오프셋에서 글꼴 모음을 검색합니다. 이름은 Google 문서 또는 Google Fonts의 글꼴 메뉴와 대소문자를 구분합니다. getFontFamily()setFontFamily(fontFamilyName) 메서드 이제 FontFamily enum 대신 글꼴에 문자열 이름을 사용합니다. 이 열거형은 이전 스크립트와의 호환성을 위해 계속 사용할 수 있습니다.

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Sets the font of the first 16 characters to Impact.
const text = body.editAsText().setFontFamily(0, 15, 'Impact');

// Gets the font family of the 16th character in the tab body.
const fontFamily = text.getFontFamily(15);

// Logs the font family to the console.
console.log(fontFamily);

매개변수

이름유형설명
offsetInteger문자 오프셋입니다.

리턴

String - 글꼴 모음입니다.

승인

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

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

getFontSize()

글꼴 크기 설정을 검색합니다.

리턴

Number: 글꼴 크기 또는 요소에 이 속성의 값이 여러 개 포함된 경우 null

승인

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

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

getFontSize(offset)

지정된 문자 오프셋에서 글꼴 크기를 검색합니다.

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Sets the font size of the first 13 characters to 15.
const text = body.editAsText().setFontSize(0, 12, 15);

// Gets the font size of the first character.
const fontSize = text.getFontSize(0);

// Logs the font size to the console.
console.log(fontSize);

매개변수

이름유형설명
offsetInteger문자 오프셋입니다.

리턴

Number - 글꼴 크기입니다.

승인

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

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

getForegroundColor()

전경 색상 설정을 검색합니다.

리턴

String: CSS 표기법 (예: '#ffffff')으로 형식이 지정된 전경 색상 또는 null 요소에 이 속성의 값이 여러 개 포함된 경우

승인

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

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

getForegroundColor(offset)

지정된 문자 오프셋의 전경 색상을 검색합니다.

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Sets the foreground color of the first 3 characters in the tab body.
const text = body.editAsText().setForegroundColor(0, 2, '#0000FF');

// Gets the foreground color of the first character in the tab body.
const foregroundColor = text.getForegroundColor(0);

// Logs the foreground color to the console.
console.log(foregroundcolor);

매개변수

이름유형설명
offsetInteger문자 오프셋입니다.

리턴

String - CSS 표기법 (예: '#ffffff')으로 형식이 지정된 전경 색상입니다.

승인

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

  • 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

getLinkUrl(offset)

지정된 문자 오프셋에 있는 링크 URL을 검색합니다.

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Applies a link to the first 10 characters in the body.
const text = body.editAsText().setLinkUrl(0, 9, 'https://www.example.com/');

// Gets the URL of the link from the first character.
const link = text.getLinkUrl(0);

// Logs the link URL to the console.
console.log(link);

매개변수

이름유형설명
offsetInteger문자 오프셋입니다.

리턴

String - 링크 URL입니다.

승인

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

  • 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

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

getTextAlignment(offset)

단일 문자의 텍스트 정렬을 가져옵니다. 사용할 수 있는 정렬 유형은 DocumentApp.TextAlignment.NORMAL, DocumentApp.TextAlignment.SUBSCRIPT, DocumentApp.TextAlignment.SUPERSCRIPT입니다.

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Sets the text alignment of the tab's body to NORMAL.
const text = body.editAsText().setTextAlignment(DocumentApp.TextAlignment.NORMAL);

// Gets the text alignment of the ninth character.
const alignment = text.getTextAlignment(8);

// Logs the text alignment to the console.
console.log(alignment.toString());

매개변수

이름유형설명
offsetInteger문자의 오프셋입니다.

리턴

TextAlignment - 텍스트 정렬 유형 또는 텍스트 정렬이 설정되지 않은 경우 null입니다.

승인

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

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

getTextAttributeIndices()

고유한 텍스트 형식의 시작 부분에 해당하는 텍스트 색인 집합을 검색합니다. 실행할 수도 있습니다

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Gets the text indices at which text formatting changes.
const indices = body.editAsText().getTextAttributeIndices();

// Logs the indices to the console.
console.log(indices.toString());

리턴

Integer[] - 텍스트 서식이 변경되는 텍스트 색인 집합입니다.

승인

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

  • 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

insertText(offset, text)

지정된 문자 오프셋에 지정된 텍스트를 삽입합니다.

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Inserts the text, 'Sample inserted text', at the start of the body content.
const text = body.editAsText().insertText(0, 'Sample inserted text');

매개변수

이름유형설명
offsetInteger텍스트를 삽입할 문자 오프셋입니다.
textString삽입할 텍스트입니다.

리턴

Text - 현재 요소입니다.

승인

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

  • 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

isBold()

굵게 설정을 검색합니다.

리턴

Boolean: 텍스트가 굵게인지, 또는 요소에 이 값에 대한 값이 여러 개 포함된 경우 null인지 여부 속성

승인

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

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

isBold(offset)

지정된 문자 오프셋에서 굵게 설정을 검색합니다.

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Bolds the first 4 characters in the tab body.
const text = body.editAsText().setBold(0, 3, true);

// Gets whether or not the text is bold.
const bold = text.editAsText().isBold(0);

// Logs the text's bold setting to the console
console.log(bold);

매개변수

이름유형설명
offsetInteger문자 오프셋입니다.

리턴

Boolean - 굵게 설정입니다.

승인

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

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

isItalic()

기울임꼴 설정을 검색합니다.

리턴

Boolean: 텍스트가 기울임꼴인지 여부, 또는 요소에 이 항목의 여러 값이 포함된 경우 null 속성

승인

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

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

isItalic(offset)

지정된 문자 오프셋에서 기울임꼴 설정을 검색합니다.

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Sets the first 13 characters of the tab body to italic.
const text = body.editAsText().setItalic(0, 12, true);

// Gets whether the fifth character in the tab body is set to
// italic and logs it to the console.
const italic = text.isItalic(4);
console.log(italic);

매개변수

이름유형설명
offsetInteger문자 오프셋입니다.

리턴

Boolean - 기울임꼴 설정입니다.

승인

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

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

isStrikethrough()

취소선 설정을 검색합니다.

리턴

Boolean: 텍스트에 취소선이 있는지 여부, 또는 요소에 여러 값이 포함된 경우 null 이 속성

승인

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

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

isStrikethrough(offset)

지정된 문자 오프셋의 취소선 설정을 검색합니다.

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Sets the first 17 characters of the tab body to strikethrough.
const text = body.editAsText().setStrikethrough(0, 16, true);

// Gets whether the first character in the tab body is set to
// strikethrough and logs it to the console.
const strikethrough = text.isStrikethrough(0);
console.log(strikethrough);

매개변수

이름유형설명
offsetInteger문자 오프셋입니다.

리턴

Boolean - 취소선 설정입니다.

승인

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

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

isUnderline()

밑줄 설정을 검색합니다.

리턴

Boolean: 텍스트에 밑줄이 있는지 여부, 또는 요소에 다음 값이 여러 개 포함된 경우 null입니다. 이 속성

승인

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

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

isUnderline(offset)

지정된 문자 오프셋에서 밑줄 설정을 검색합니다.

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Sets the first 13 characters of the tab body to underline.
const text = body.editAsText().setUnderline(0, 12, false);

// Gets whether the first character in the tab body is set to
// underline and logs it to the console
const underline = text.editAsText().isUnderline(0);
console.log(underline);

매개변수

이름유형설명
offsetInteger문자 오프셋입니다.

리턴

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();

리턴

Text - 병합된 요소입니다.

승인

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

  • 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();
}

리턴

Text - 삭제된 요소입니다.

승인

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

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

replaceText(searchPattern, replacement)

정규식을 사용하여 지정된 텍스트 패턴과 일치하는 모든 항목을 지정된 대체 문자열로 바꿉니다. 식을 사용할 수 있습니다.

검색 패턴은 JavaScript 정규 표현식 객체가 아닌 문자열로 전달됩니다. 따라서 패턴에서 백슬래시를 이스케이프 처리해야 합니다.

이 방법은 Google의 RE2 일반 표현식 라이브러리를 사용할 수 있습니다. 이 API는 지원되는 구문을 제한합니다.

제공된 정규 표현식 패턴이 각 텍스트 블록과 독립적으로 일치됩니다. .

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

// Clear the text surrounding "Apps Script", with or without text.
body.replaceText("^.*Apps ?Script.*$", "Apps Script");

매개변수

이름유형설명
searchPatternString검색할 정규식 패턴
replacementString대체로 사용할 텍스트

리턴

Element: 현재 요소

승인

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

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

setAttributes(startOffset, endOffsetInclusive, attributes)

지정된 속성을 지정된 문자 범위에 적용합니다.

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

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Declares style attributes for font size and font family.
const style = {}
style[DocumentApp.Attribute.FONT_SIZE] = 20 ;
style[DocumentApp.Attribute.FONT_FAMILY] = 'Impact';

// Sets the style attributes to the first 9 characters in the tab's body.
const text = body.setAttributes(0, 8, style);

매개변수

이름유형설명
startOffsetInteger텍스트 범위의 시작 오프셋입니다.
endOffsetInclusiveInteger텍스트 범위의 끝 오프셋입니다.
attributesObject요소의 속성입니다.

리턴

Text - 현재 요소입니다.

승인

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

  • 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요소의 속성입니다.

리턴

Text - 현재 요소입니다.

승인

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

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

setBackgroundColor(startOffset, endOffsetInclusive, color)

지정된 문자 범위의 배경 색상을 설정합니다.

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Sets the background color of the first 3 characters in the
// tab body to hex color #0000FF.
const text = body.editAsText().setBackgroundColor(0, 2, '#0000FF');

매개변수

이름유형설명
startOffsetInteger텍스트 범위의 시작 오프셋입니다.
endOffsetInclusiveInteger텍스트 범위의 끝 오프셋입니다.
colorStringCSS 표기법 (예: '#ffffff')으로 형식이 지정된 배경 색상입니다.

리턴

Text - 현재 요소입니다.

승인

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

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

setBackgroundColor(color)

배경 색상을 설정합니다.

매개변수

이름유형설명
colorStringCSS 표기법으로 형식이 지정된 배경 색상 (예: '#ffffff')

리턴

Text: 현재 요소

승인

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

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

setBold(bold)

굵게 설정을 설정합니다.

매개변수

이름유형설명
boldBoolean굵게 설정

리턴

Text: 현재 요소

승인

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

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

setBold(startOffset, endOffsetInclusive, bold)

지정된 문자 범위에 굵게 설정을 설정합니다.

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Sets the first 11 characters in the tab's body to bold.
const text = body.editAsText().setBold(0, 10, true);

매개변수

이름유형설명
startOffsetInteger텍스트 범위의 시작 오프셋입니다.
endOffsetInclusiveInteger텍스트 범위의 끝 오프셋입니다.
boldBoolean굵게 설정

리턴

Text - 현재 요소입니다.

승인

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

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

setFontFamily(startOffset, endOffsetInclusive, fontFamilyName)

지정된 문자 범위의 글꼴 모음을 설정합니다. 이름은 글꼴의 모든 글꼴 또는 문서 또는 Google Fonts 메뉴 중 하나에서 작동하며 대소문자를 구분합니다. 인식할 수 없는 글꼴 이름은 Arial로 렌더링됩니다. getFontFamily(offset) 메서드와 이제 setFontFamily(fontFamilyName)FontFamily enum 대신 글꼴에 문자열 이름을 사용합니다. 이 열거형은 이전 스크립트와의 호환성을 위해 계속 사용할 수 있습니다.

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Sets the font of the first 4 characters in the tab's body to Roboto.
const text = body.editAsText().setFontFamily(0, 3, 'Roboto');

매개변수

이름유형설명
startOffsetInteger텍스트 범위의 시작 오프셋입니다.
endOffsetInclusiveInteger텍스트 범위의 끝 오프셋입니다.
fontFamilyNameStringDocs 또는 Google Fonts의 글꼴 메뉴에 있는 글꼴 모음의 이름입니다.

리턴

Text - 현재 요소입니다.

승인

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

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

setFontFamily(fontFamilyName)

글꼴 모음을 설정합니다. 이름은 Docs의 글꼴 메뉴 또는 Google Fonts에 있는 모든 글꼴로 지정할 수 있으며 대소문자를 구분합니다. 인식할 수 없는 글꼴 Arial로 렌더링됩니다. 이제 getFontFamily()setFontFamily(fontFamilyName) 메서드가 FontFamily enum 대신 글꼴에 문자열 이름을 사용합니다. 이 열거형은 이전 스크립트와의 호환성을 위해 계속 사용할 수 있습니다.

매개변수

이름유형설명
fontFamilyNameStringDocs 또는 Google Fonts의 글꼴 메뉴에서 글꼴 모음 이름

리턴

Text: 현재 요소

승인

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

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

setFontSize(startOffset, endOffsetInclusive, size)

지정된 문자 범위의 글꼴 크기를 설정합니다.

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Sets the size of the first 11 characters in the tab's body to 12.
const text = body.editAsText().setFontSize(0, 10, 12);

매개변수

이름유형설명
startOffsetInteger텍스트 범위의 시작 오프셋입니다.
endOffsetInclusiveInteger텍스트 범위의 끝 오프셋입니다.
sizeNumber글꼴 크기입니다.

리턴

Text - 현재 요소입니다.

승인

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

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

setFontSize(size)

글꼴 크기를 설정합니다.

매개변수

이름유형설명
sizeNumber글꼴 크기

리턴

Text: 현재 요소

승인

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

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

setForegroundColor(startOffset, endOffsetInclusive, color)

지정된 문자 범위의 전경 색상을 설정합니다.

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Sets the foreground color of the first 2 characters in the
// tab's body to hex color #FF0000.
const text = body.editAsText().setForegroundColor(0, 1, '#FF0000');

// Gets the foreground color for the second character in the tab's body.
const foregroundColor = text.getForegroundColor(1);

//  Logs the foreground color to the console.
console.log(foregroundColor);

매개변수

이름유형설명
startOffsetInteger텍스트 범위의 시작 오프셋입니다.
endOffsetInclusiveInteger텍스트 범위의 끝 오프셋입니다.
colorStringCSS 표기법 (예: '#ffffff')으로 형식이 지정된 전경 색상입니다.

리턴

Text - 현재 요소입니다.

승인

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

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

setForegroundColor(color)

전경 색상을 설정합니다.

매개변수

이름유형설명
colorStringCSS 표기법으로 형식이 지정된 전경 색상 (예: '#ffffff')

리턴

Text: 현재 요소

승인

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

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

setItalic(italic)

기울임꼴 설정을 설정합니다.

매개변수

이름유형설명
italicBoolean기울임꼴 설정

리턴

Text: 현재 요소

승인

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

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

setItalic(startOffset, endOffsetInclusive, italic)

지정된 문자 범위에 대해 기울임꼴 설정을 설정합니다.

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Sets the first 11 characters in the tab's body to italic.
const text = body.editAsText().setItalic(0, 10, true);

매개변수

이름유형설명
startOffsetInteger텍스트 범위의 시작 오프셋입니다.
endOffsetInclusiveInteger텍스트 범위의 끝 오프셋입니다.
italicBoolean기울임꼴 설정입니다.

리턴

Text - 현재 요소입니다.

승인

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

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

setLinkUrl(startOffset, endOffsetInclusive, url)

지정된 문자 범위에 대한 링크 URL을 설정합니다.

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Applies a link to the first 11 characters in the body.
const text = body.editAsText().setLinkUrl(0, 10, 'https://example.com');

매개변수

이름유형설명
startOffsetInteger텍스트 범위의 시작 오프셋입니다.
endOffsetInclusiveInteger텍스트 범위의 끝 오프셋입니다.
urlString링크 URL입니다.

리턴

Text - 현재 요소입니다.

승인

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

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

setLinkUrl(url)

링크 URL을 설정합니다.

매개변수

이름유형설명
urlString링크 URL

리턴

Text: 현재 요소

승인

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

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

setStrikethrough(strikethrough)

취소선 설정을 설정합니다.

매개변수

이름유형설명
strikethroughBoolean취소선 설정을

리턴

Text: 현재 요소

승인

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

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

setStrikethrough(startOffset, endOffsetInclusive, strikethrough)

지정된 문자 범위에 취소선 설정을 설정합니다.

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Sets the first 11 characters in the tab's body to strikethrough.
const text = body.editAsText().setStrikethrough(0, 10, true);

매개변수

이름유형설명
startOffsetInteger텍스트 범위의 시작 오프셋입니다.
endOffsetInclusiveInteger텍스트 범위의 끝 오프셋입니다.
strikethroughBoolean취소선 설정입니다.

리턴

Text - 현재 요소입니다.

승인

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

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

setText(text)

텍스트 콘텐츠를 설정합니다.

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Replaces the contents of the body with the text, 'New body text.'
const text = body.editAsText().setText('New body text.');

매개변수

이름유형설명
textString새 텍스트 콘텐츠입니다.

리턴

Text - 현재 요소입니다.

승인

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

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

setTextAlignment(startOffset, endOffsetInclusive, textAlignment)

지정된 문자 범위의 텍스트 정렬을 설정합니다. 사용할 수 있는 정렬 유형은 다음과 같습니다. DocumentApp.TextAlignment.NORMAL, DocumentApp.TextAlignment.SUBSCRIPTDocumentApp.TextAlignment.SUPERSCRIPT입니다.

// Make the first character in the first paragraph of the active tab be superscript.
var documentTab = DocumentApp.getActiveDocument().getActiveTab().asDocumentTab();
var text = documentTab.getBody().getParagraphs()[0].editAsText();
text.setTextAlignment(0, 0, DocumentApp.TextAlignment.SUPERSCRIPT);

매개변수

이름유형설명
startOffsetInteger문자 범위의 시작 오프셋입니다.
endOffsetInclusiveInteger문자 범위의 끝 오프셋입니다 (해당 값 포함).
textAlignmentTextAlignment적용할 텍스트 정렬 유형입니다.

리턴

Text - 현재 요소입니다.

승인

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

  • 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 in the active tab be superscript.
var documentTab = DocumentApp.getActiveDocument().getActiveTab().asDocumentTab();
var text = documentTab.getBody().getParagraphs()[0].editAsText();
text.setTextAlignment(DocumentApp.TextAlignment.SUPERSCRIPT);

매개변수

이름유형설명
textAlignmentTextAlignment적용할 텍스트 정렬 유형

리턴

Text: 현재 요소

승인

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

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

setUnderline(underline)

밑줄 설정을 설정합니다.

매개변수

이름유형설명
underlineBoolean밑줄 설정

리턴

Text: 현재 요소

승인

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

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

setUnderline(startOffset, endOffsetInclusive, underline)

지정된 문자 범위에 밑줄 설정을 설정합니다.

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Sets the first 11 characters in the tab's body to underline.
const text = body.editAsText().setUnderline(0, 10, true);

매개변수

이름유형설명
startOffsetInteger텍스트 범위의 시작 오프셋입니다.
endOffsetInclusiveInteger텍스트 범위의 끝 오프셋입니다.
underlineBoolean밑줄 설정입니다.

리턴

Text - 현재 요소입니다.

승인

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

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