Class Table

테이블을 나타내는 요소입니다. Table에는 TableRow 요소만 포함될 수 있습니다. 문서 구조에 관한 자세한 내용은 Google 문서 확장 가이드를 참고하세요.

많은 수의 행이나 셀을 포함하는 Table를 만드는 경우 다음 예와 같이 문자열 배열로 빌드하는 것이 좋습니다.

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

// Create a two-dimensional array containing the 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.
body.appendTable(cells);

방법

메서드반환 유형간략한 설명
appendTableRow()TableRowTableRow를 만들고 추가합니다.
appendTableRow(tableRow)TableRow지정된 TableRow를 추가합니다.
clear()Table요소의 콘텐츠를 지웁니다.
copy()Table현재 요소의 분리된 전체 사본을 반환합니다.
editAsText()Text수정을 위해 현재 요소의 Text 버전을 가져옵니다.
findElement(elementType)RangeElement요소의 콘텐츠에서 지정된 유형의 하위 요소를 검색합니다.
findElement(elementType, from)RangeElement지정된 RangeElement에서 시작하여 지정된 유형의 하위 요소를 위해 요소의 콘텐츠를 검색합니다.
findText(searchPattern)RangeElement정규 표현식을 사용하여 지정된 텍스트 패턴에서 요소의 콘텐츠를 검색합니다.
findText(searchPattern, from)RangeElement지정된 검색 결과부터 지정된 텍스트 패턴의 요소 콘텐츠를 검색합니다.
getAttributes()Object요소의 속성을 검색합니다.
getBorderColor()String테두리 색상을 검색합니다.
getBorderWidth()Number테두리 너비를 포인트 단위로 검색합니다.
getCell(rowIndex, cellIndex)TableCell지정된 행과 셀 색인에서 TableCell를 검색합니다.
getChild(childIndex)Element지정된 하위 색인에서 하위 요소를 검색합니다.
getChildIndex(child)Integer지정된 하위 요소의 하위 색인을 검색합니다.
getColumnWidth(columnIndex)Number지정된 표 열의 너비를 포인트 단위로 검색합니다.
getLinkUrl()String링크 URL을 검색합니다.
getNextSibling()Element요소의 다음 동위 요소를 검색합니다.
getNumChildren()Integer하위 요소 수를 검색합니다.
getNumRows()IntegerTableRows 수를 검색합니다.
getParent()ContainerElement요소의 상위 요소를 검색합니다.
getPreviousSibling()Element요소의 이전 동위 요소를 검색합니다.
getRow(rowIndex)TableRow지정된 행 색인에서 TableRow를 검색합니다.
getText()String요소의 콘텐츠를 텍스트 문자열로 검색합니다.
getTextAlignment()TextAlignment텍스트 정렬을 가져옵니다.
getType()ElementType요소의 ElementType를 검색합니다.
insertTableRow(childIndex)TableRow지정된 색인에 새 TableRow를 만들고 삽입합니다.
insertTableRow(childIndex, tableRow)TableRow지정된 색인에 지정된 TableRow를 삽입합니다.
isAtDocumentEnd()Boolean요소가 Document의 끝에 있는지 확인합니다.
removeChild(child)Table지정된 하위 요소를 삭제합니다.
removeFromParent()Table상위 항목에서 요소를 삭제합니다.
removeRow(rowIndex)TableRow지정된 행 색인에서 TableRow를 삭제합니다.
replaceText(searchPattern, replacement)Element정규 표현식을 사용하여 지정된 텍스트 패턴과 일치하는 모든 항목을 지정된 대체 문자열로 바꿉니다.
setAttributes(attributes)Table요소의 속성을 설정합니다.
setBorderColor(color)Table테두리 색상을 설정합니다.
setBorderWidth(width)Table테두리 너비를 포인트 단위로 설정합니다.
setColumnWidth(columnIndex, width)Table지정된 열의 너비를 포인트 단위로 설정합니다.
setLinkUrl(url)Table링크 URL을 설정합니다.
setTextAlignment(textAlignment)Table텍스트 정렬을 설정합니다.

자세한 문서

appendTableRow()

TableRow를 만들고 추가합니다.

리턴

TableRow - 새 테이블 행 요소

승인

이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.

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

appendTableRow(tableRow)

지정된 TableRow를 추가합니다.

// 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 table in the document and copies the second row.
const table = body.getTables()[0];
const row = table.getChild(1).copy();

// Adds the copied row to the bottom of the table.
const tableRow = table.appendTableRow(row);

매개변수

이름유형설명
tableRowTableRow추가할 테이블 행입니다.

리턴

TableRow - 추가된 테이블 행 요소입니다.

승인

이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.

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

clear()

요소의 콘텐츠를 지웁니다.

리턴

Table: 현재 요소


copy()

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

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

리턴

Table - 새 사본입니다.

승인

이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.

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

editAsText()

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

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

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

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)

요소의 콘텐츠에서 지정된 유형의 하위 요소를 검색합니다.

매개변수

이름유형설명
elementTypeElementType검색할 요소의 유형

리턴

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;
  }
}

매개변수

이름유형설명
elementTypeElementType검색할 요소의 유형
fromRangeElement검색할 검색결과

리턴

RangeElement: 검색 요소의 다음 위치를 나타내는 검색결과

승인

이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.

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

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 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

getBorderColor()

테두리 색상을 검색합니다.

// 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 table.
const table = body.getTables()[0];

// Sets the border color of the first table.
table.setBorderColor('#00FF00');

// Logs the border color of the first table to the console.
console.log(table.getBorderColor());

리턴

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

승인

이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.

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

getBorderWidth()

테두리 너비를 포인트 단위로 검색합니다.

// 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 table.
const table = body.getTables()[0];

// Sets the border width of the first table.
table.setBorderWidth(20);

// Logs the border width of the first table.
console.log(table.getBorderWidth());

리턴

Number - 테두리 너비(포인트)

승인

이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.

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

getCell(rowIndex, cellIndex)

지정된 행과 셀 색인에서 TableCell를 검색합니다.

// 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 table.
const table = body.getTables()[0];

// Gets the cell of the table's third row and second column.
const cell = table.getCell(2, 1);

// Logs the cell text to the console.
console.log(cell.getText());

매개변수

이름유형설명
rowIndexInteger검색할 셀이 포함된 행의 색인입니다.
cellIndexInteger검색할 셀의 색인입니다.

리턴

TableCell - 표 셀입니다.

승인

이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.

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

매개변수

이름유형설명
childIndexInteger검색할 하위 요소의 색인

리턴

Element - 지정된 색인의 하위 요소

승인

이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.

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

getChildIndex(child)

지정된 하위 요소의 하위 색인을 검색합니다.

매개변수

이름유형설명
childElement색인을 검색할 하위 요소

리턴

Integer: 하위 색인

승인

이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.

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

getColumnWidth(columnIndex)

지정된 표 열의 너비를 포인트 단위로 검색합니다.

// 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 table.
const table = body.getTables()[0];

// Sets the width of the second column to 100 points.
const columnWidth = table.setColumnWidth(1, 100);

// Gets the width of the second column and logs it to the console.
console.log(columnWidth.getColumnWidth(1));

매개변수

이름유형설명
columnIndexInteger열 색인입니다.

리턴

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

요소의 다음 동위 요소를 검색합니다.

다음 동위 요소는 동일한 상위 요소를 가지며 현재 요소를 따릅니다.

리턴

Element - 다음 동위 요소

승인

이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.

  • 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.");

리턴

Integer: 하위 요소의 수

승인

이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.

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

getNumRows()

TableRows 수를 검색합니다.

// 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 table.
const table = body.getTables()[0];

// Logs the number of rows of the first table to the console.
console.log(table.getNumRows());

리턴

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

getPreviousSibling()

요소의 이전 동위 요소를 검색합니다.

이전 동위 요소가 동일한 상위 요소를 가지며 현재 요소 앞에 옵니다.

리턴

Element - 이전의 동위 요소

승인

이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.

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

getRow(rowIndex)

지정된 행 색인에서 TableRow를 검색합니다.

// 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 table and logs the text of first row to the console.
const table = body.getTables()[0];
console.log(table.getRow(0).getText());

매개변수

이름유형설명
rowIndexInteger검색할 행의 색인입니다.

리턴

TableRow - 표의 행입니다.

승인

이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.

  • 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

insertTableRow(childIndex)

지정된 색인에 새 TableRow를 만들고 삽입합니다.

매개변수

이름유형설명
childIndexInteger요소를 삽입할 색인

리턴

TableRow: 현재 요소

승인

이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.

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

insertTableRow(childIndex, tableRow)

지정된 색인에 지정된 TableRow를 삽입합니다.

매개변수

이름유형설명
childIndexInteger요소를 삽입할 색인
tableRowTableRow삽입할 테이블 행

리턴

TableRow — 삽입된 테이블 행 요소

승인

이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.

  • 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

removeChild(child)

지정된 하위 요소를 삭제합니다.

// 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 table.
const table = body.getTables()[0];

// Finds the first table row and removes it.
const element = table.findElement(DocumentApp.ElementType.TABLE_ROW);
table.removeChild(element.getElement());

매개변수

이름유형설명
childElement삭제할 하위 요소입니다.

리턴

Table - 현재 요소입니다.

승인

이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.

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

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

리턴

Table - 삭제된 요소입니다.

승인

이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.

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

removeRow(rowIndex)

지정된 행 색인에서 TableRow를 삭제합니다.

// 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 table and removes its second row.
const table = body.getTables()[0];
table.removeRow(1);

매개변수

이름유형설명
rowIndexInteger제거할 행의 색인입니다.

리턴

TableRow - 삭제된 행입니다.

승인

이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.

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

replaceText(searchPattern, replacement)

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

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

이 메서드는 지원되는 구문을 제한하는 Google의 RE2 정규 표현식 라이브러리를 사용합니다.

제공된 정규 표현식 패턴은 현재 요소에 포함된 각 텍스트 블록과 독립적으로 일치됩니다.

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

매개변수

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

리턴

Table - 현재 요소입니다.

승인

이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.

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

setBorderColor(color)

테두리 색상을 설정합니다.

// 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 table.
const table = body.getTables()[0];

// Sets the border color of the table to green.
table.setBorderColor('#00FF00');

매개변수

이름유형설명
colorStringCSS 표기법 (예: '#ffffff')으로 형식이 지정된 테두리 색상입니다.

리턴

Table - 현재 요소입니다.

승인

이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.

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

setBorderWidth(width)

테두리 너비를 포인트 단위로 설정합니다.

매개변수

이름유형설명
widthNumber테두리 너비(포인트)

리턴

Table: 현재 요소

승인

이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.

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

setColumnWidth(columnIndex, width)

지정된 열의 너비를 포인트 단위로 설정합니다.

매개변수

이름유형설명
columnIndexInteger열 색인
widthNumber테두리 너비(포인트)

리턴

Table: 현재 요소

승인

이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.

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

setLinkUrl(url)

링크 URL을 설정합니다.

매개변수

이름유형설명
urlString링크 URL

리턴

Table: 현재 요소

승인

이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.

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

매개변수

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

리턴

Table: 현재 요소

승인

이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.

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