Class DocumentTab

문서

서식 있는 텍스트와 표, 목록 등의 요소가 포함된 문서 탭

Document.getTabs()[tabIndex].asDocumentTab()을 사용하여 문서 탭을 가져옵니다.

// Get a specific document tab based on the tab ID.
// TODO(developer): Replace the IDs with your own.
const documentTab =
    DocumentApp.openById('123abc').getTab('123abc').asDocumentTab();

메서드

메서드반환 유형간략한 설명
addBookmark(position)Bookmark지정된 PositionBookmark를 추가합니다.
addFooter()FooterSection탭 바닥글 섹션이 없는 경우 추가합니다.
addHeader()HeaderSection탭 헤더 섹션이 없는 경우 추가합니다.
addNamedRange(name, range)NamedRange나중에 검색하는 데 사용할 이름과 ID가 있는 RangeNamedRange를 추가합니다.
getBody()Body탭의 Body를 가져옵니다.
getBookmark(id)Bookmark|null지정된 ID의 Bookmark을 가져옵니다.
getBookmarks()Bookmark[]탭의 모든 Bookmark 객체를 가져옵니다.
getFooter()FooterSection|null탭의 바닥글 섹션을 가져옵니다(있는 경우).
getFootnotes()Footnote[]|null탭 본문의 모든 Footnote 요소를 가져옵니다.
getHeader()HeaderSection|null탭의 헤더 섹션을 가져옵니다(있는 경우).
getNamedRangeById(id)NamedRange|null지정된 ID의 NamedRange을 가져옵니다.
getNamedRanges()NamedRange[]탭의 모든 NamedRange 객체를 가져옵니다.
getNamedRanges(name)NamedRange[]지정된 이름의 탭에 있는 모든 NamedRange 객체를 가져옵니다.
newPosition(element, offset)Position특정 요소를 기준으로 탭의 위치를 참조하는 새 Position를 만듭니다.
newRange()RangeBuilder탭 요소에서 Range 객체를 구성하는 데 사용되는 빌더를 만듭니다.

자세한 문서

addBookmark(position)

지정된 PositionBookmark를 추가합니다.

// Opens the Docs file and retrieves the tab by its IDs. If you created your
// script from within a Google Docs file, you can use
// DocumentApp.getActiveDocument().getActiveTab() instead.
// TODO(developer): Replace the IDs with your own.
const documentTab =
    DocumentApp.openById('123abc').getTab('123abc').asDocumentTab();

// Gets the tab body and adds a paragraph.
const paragraph = documentTab.getBody().appendParagraph('My new paragraph.');

// Creates a position at the first character of the paragraph text.
const position = documentTab.newPosition(paragraph.getChild(0), 0);

// Adds a bookmark at the first character of the paragraph text.
const bookmark = documentTab.addBookmark(position);

// Logs the bookmark ID to the console.
console.log(bookmark.getId());

매개변수

이름유형설명
positionPosition새 북마크의 위치입니다.

리턴

Bookmark - 새 북마크입니다.

승인

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

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

addFooter()

탭 바닥글 섹션이 없는 경우 추가합니다.

// Opens the Docs file and retrieves the tab by its IDs. If you created your
// script from within a Google Docs file, you can use
// DocumentApp.getActiveDocument().getActiveTab() instead.
// TODO(developer): Replace the IDs with your own.
const documentTab =
    DocumentApp.openById('123abc').getTab('123abc').asDocumentTab();

// Adds a footer to the tab.
const footer = documentTab.addFooter();

// Sets the footer text to 'This is a footer.'
footer.setText('This is a footer');

리턴

FooterSection - 탭 바닥글입니다.

승인

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

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

addHeader()

탭 헤더 섹션이 없는 경우 추가합니다.

// Opens the Docs file and retrieves the tab by its IDs. If you created your
// script from within a Google Docs file, you can use
// DocumentApp.getActiveDocument().getActiveTab() instead.
// TODO(developer): Replace the IDs with your own.
const documentTab =
    DocumentApp.openById('123abc').getTab('123abc').asDocumentTab();

// Adds a header to the tab.
const header = documentTab.addHeader();

// Sets the header text to 'This is a header.'
header.setText('This is a header');

리턴

HeaderSection - 탭 헤더입니다.

승인

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

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

addNamedRange(name, range)

나중에 검색하는 데 사용할 이름과 ID가 있는 RangeNamedRange를 추가합니다. 이름은 탭 간에도 반드시 고유하지는 않습니다. HTML의 클래스와 마찬가지로 동일한 문서의 여러 범위가 동일한 이름을 공유할 수 있습니다. 반면 ID는 HTML의 ID와 같이 문서 내에서 고유합니다. NamedRange를 추가한 후에는 수정할 수 없으며 삭제만 가능합니다.

탭에 액세스하는 스크립트는 NamedRange에 액세스할 수 있습니다. 스크립트 간의 의도치 않은 충돌을 방지하려면 범위 이름에 고유한 문자열을 접두사로 추가하는 것이 좋습니다.

// Creates a named range that includes every table in a tab by its ID.
// TODO(developer): Replace the IDs with your own.
const documentTab =
    DocumentApp.openById('123abc').getTab('123abc').asDocumentTab();
const rangeBuilder = documentTab.newRange();
const tables = documentTab.getBody().getTables();
for (let i = 0; i < tables.length; i++) {
  rangeBuilder.addElement(tables[i]);
}
documentTab.addNamedRange('Tab t.0 tables', rangeBuilder.build());

매개변수

이름유형설명
nameString범위의 이름입니다. 고유하지 않아도 됩니다. 범위 이름은 1~256자여야 합니다.
rangeRange이름과 연결할 요소의 범위입니다. 범위는 검색 결과일 수도 있고 newRange()로 수동으로 구성할 수도 있습니다.

리턴

NamedRange - NamedRange

승인

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

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

getBody()

탭의 Body를 가져옵니다.

탭에는 다양한 유형의 섹션 (예: HeaderSection, FooterSection)이 포함될 수 있습니다. 탭의 활성 섹션은 Body입니다.

DocumentTab의 요소 메서드는 Body에 위임됩니다.

// Opens the Docs file and retrieves the tab by its IDs. If you created your
// script from within a Google Docs file, you can use
// DocumentApp.getActiveDocument().getActiveTab() instead.
// TODO(developer): Replace the IDs with your own.
const documentTab =
    DocumentApp.openById('123abc').getTab('123abc').asDocumentTab();

// Gets the tab body.
const body = documentTab.getBody();

// Gets the body text and logs it to the console.
console.log(body.getText());

리턴

Body - 탭의 본문 섹션입니다.

승인

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

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

getBookmark(id)

지정된 ID의 Bookmark을 가져옵니다. 이 탭에 이러한 Bookmark이 없으면 이 메서드는 null을 반환합니다.

// Opens the Docs file and retrieves the tab by its IDs. If you created your
// script from within a Google Docs file, you can use
// DocumentApp.getActiveDocument().getActiveTab() instead.
// TODO(developer): Replace the IDs with your own.
const documentTab =
    DocumentApp.openById('123abc').getTab('123abc').asDocumentTab();

// Gets the bookmark by its ID.
const bookmark = documentTab.getBookmark('id.xyz654321');

// If the bookmark exists within the tab, logs the character offset of its
// position to the console. Otherwise, logs 'No bookmark exists with the given
// ID.' to the console.
if (bookmark) {
  console.log(bookmark.getPosition().getOffset());
} else {
  console.log('No bookmark exists with the given ID.');
}

매개변수

이름유형설명
idStringBookmark의 ID입니다.

리턴

Bookmark|null - 지정된 ID가 있는 Bookmark 또는 탭 내에 이러한 Bookmark이 없는 경우 null입니다.

승인

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

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

getBookmarks()

탭의 모든 Bookmark 객체를 가져옵니다.

// Opens the Docs file and retrieves the tab by its IDs. If you created your
// script from within a Google Docs file, you can use
// DocumentApp.getActiveDocument().getActiveTab() instead.
// TODO(developer): Replace the IDs with your own.
const documentTab =
    DocumentApp.openById('123abc').getTab('123abc').asDocumentTab();

// Gets all of the bookmarks in the tab.
const bookmarks = documentTab.getBookmarks();

// Logs the number of bookmarks in the tab to the console.
console.log(bookmarks.length);

리턴

Bookmark[] - 탭에 있는 Bookmark 객체의 배열입니다.

승인

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

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

getFooter()

탭의 바닥글 섹션을 가져옵니다(있는 경우).

// Opens the Docs file and retrieves the tab by its IDs. If you created your
// script from within a Google Docs file, you can use
// DocumentApp.getActiveDocument().getActiveTab() instead.
// TODO(developer): Replace the IDs with your own.
const documentTab =
    DocumentApp.openById('123abc').getTab('123abc').asDocumentTab();

// Gets the text of the tab's footer and logs it to the console.
console.log(documentTab.getFooter().getText());

리턴

FooterSection|null - 탭의 바닥글입니다.

승인

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

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

getFootnotes()

탭 본문의 모든 Footnote 요소를 가져옵니다.

getFootnotes 호출은 탭의 요소에 대한 반복을 유발합니다. 큰 탭의 경우 이 메서드를 불필요하게 호출하지 마세요.

// Opens the Docs file and retrieves the tab by its IDs. If you created your
// script from within a Google Docs file, you can use
// DocumentApp.getActiveDocument().getActiveTab() instead.
// TODO(developer): Replace the IDs with your own.
const documentTab =
    DocumentApp.openById('123abc').getTab('123abc').asDocumentTab();

// Gets the first footnote.
const footnote = documentTab.getFootnotes()[0];

// Logs footnote contents to the console.
console.log(footnote.getFootnoteContents().getText());

리턴

Footnote[]|null - 탭의 각주입니다.

승인

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

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

getHeader()

탭의 헤더 섹션을 가져옵니다(있는 경우).

// Opens the Docs file and retrieves the tab by its IDs. If you created your
// script from within a Google Docs file, you can use
// DocumentApp.getActiveDocument().getActiveTab() instead.
// TODO(developer): Replace the IDs with your own.
const documentTab =
    DocumentApp.openById('123abc').getTab('123abc').asDocumentTab();

// Gets the text of the tab's header and logs it to the console.
console.log(documentTab.getHeader().getText());

리턴

HeaderSection|null - 탭의 헤더입니다.

승인

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

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

getNamedRangeById(id)

지정된 ID의 NamedRange을 가져옵니다. 이 메서드는 탭에 이러한 NamedRange이 없으면 null를 반환합니다. 이름은 탭 간에도 반드시 고유하지는 않습니다. 동일한 문서의 여러 범위가 HTML의 클래스와 마찬가지로 동일한 이름을 공유할 수 있습니다. 반면 ID는 HTML의 ID와 같이 탭 내에서 고유합니다.

매개변수

이름유형설명
idString탭 내에서 고유한 범위의 ID입니다.

리턴

NamedRange|null - 지정된 ID가 있는 NamedRange입니다. 탭에 이러한 범위가 없으면 null입니다.

승인

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

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

getNamedRanges()

탭의 모든 NamedRange 객체를 가져옵니다.

NamedRange는 탭에 액세스하는 모든 스크립트에서 액세스할 수 있습니다. 스크립트 간의 의도치 않은 충돌을 방지하려면 범위 이름에 고유한 문자열을 접두사로 추가하는 것이 좋습니다.

리턴

NamedRange[] - 탭에 있는 NamedRange 객체의 배열로, 이름이 같은 범위가 여러 개 포함될 수 있습니다.

승인

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

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

getNamedRanges(name)

지정된 이름의 탭에 있는 모든 NamedRange 객체를 가져옵니다. 이름은 탭 간에도 반드시 고유하지는 않습니다. HTML의 클래스와 마찬가지로 동일한 문서의 여러 범위가 동일한 이름을 공유할 수 있습니다. 반면 ID는 HTML의 ID와 같이 탭 내에서 고유합니다.

NamedRange는 탭에 액세스하는 모든 스크립트에서 액세스할 수 있습니다. 스크립트 간의 의도치 않은 충돌을 방지하려면 범위 이름에 고유한 문자열을 접두사로 추가하는 것이 좋습니다.

매개변수

이름유형설명
nameString범위의 이름입니다. 고유하지 않아도 됩니다.

리턴

NamedRange[] - 지정된 이름의 탭에 있는 NamedRange 객체의 배열입니다.

승인

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

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

newPosition(element, offset)

특정 요소를 기준으로 탭의 위치를 참조하는 새 Position를 만듭니다. 사용자의 커서는 다른 용도와 함께 Position로 표시됩니다.

// Append a paragraph, then place the user's cursor after the first word of the
// new paragraph.
// TODO(developer): Replace the IDs with your own.
const doc = DocumentApp.openById('123abc');
const documentTab = doc.getTab('123abc').asDocumentTab();
const paragraph = documentTab.getBody().appendParagraph('My new paragraph.');
const position = documentTab.newPosition(paragraph.getChild(0), 2);
doc.setCursor(position);

매개변수

이름유형설명
elementElement새로 생성된 Position를 포함하는 요소입니다. Text 요소 또는 Paragraph과 같은 컨테이너 요소여야 합니다.
offsetIntegerText 요소의 경우 Position 앞의 문자 수입니다. 다른 요소의 경우 동일한 컨테이너 요소 내에서 Position 앞의 하위 요소 수입니다.

리턴

Position - 새 Position입니다.

승인

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

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

newRange()

탭 요소에서 Range 객체를 구성하는 데 사용되는 빌더를 만듭니다.

// Change the user's selection to a range that includes every table in the tab.
// TODO(developer): Replace the IDs with your own.
const doc = DocumentApp.openById('123abc');
const documentTab = doc.getTab('123abc').asDocumentTab();
const rangeBuilder = documentTab.newRange();
const tables = documentTab.getBody().getTables();
for (let i = 0; i < tables.length; i++) {
  rangeBuilder.addElement(tables[i]);
}
doc.setSelection(rangeBuilder.build());

리턴

RangeBuilder - 새로운 빌더입니다.

승인

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

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