Class Document

문서

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

DocumentApp을(를) 사용하여 문서를 열거나 만들 수 있습니다.

// Open a document by ID.
var doc = DocumentApp.openById("<my-id>");

// Create and open a document.
doc = DocumentApp.create("Document Title");

방법

메서드반환 유형간략한 설명
addBookmark(position)Bookmark지정된 PositionBookmark를 추가합니다.
addEditor(emailAddress)Document지정된 사용자를 Document의 편집자 목록에 추가합니다.
addEditor(user)Document지정된 사용자를 Document의 편집자 목록에 추가합니다.
addEditors(emailAddresses)Document지정된 사용자 배열을 Document의 편집기 목록에 추가합니다.
addFooter()FooterSection문서 바닥글 섹션이 없는 경우 추가합니다.
addHeader()HeaderSection문서 헤더 섹션이 없는 경우 추가합니다.
addNamedRange(name, range)NamedRange나중에 검색할 때 사용할 이름과 ID가 있는 RangeNamedRange를 추가합니다.
addViewer(emailAddress)Document지정된 사용자를 Document의 뷰어 목록에 추가합니다.
addViewer(user)Document지정된 사용자를 Document의 뷰어 목록에 추가합니다.
addViewers(emailAddresses)Document지정된 사용자 배열을 Document의 뷰어 목록에 추가합니다.
getAs(contentType)Blob현재 Document 콘텐츠를 지정된 유형의 blob으로 검색합니다.
getBlob()Blob현재 Document 콘텐츠를 blob으로 검색합니다.
getBody()Body활성 문서의 Body를 검색합니다.
getBookmark(id)Bookmark지정된 ID로 Bookmark를 가져옵니다.
getBookmarks()Bookmark[]문서의 모든 Bookmark 객체를 가져옵니다.
getCursor()Position활성 문서에서 사용자의 커서를 가져옵니다.
getEditors()User[]Document의 편집자 목록을 가져옵니다.
getFooter()FooterSection문서의 바닥글이 있는 경우 검색합니다.
getFootnotes()Footnote[]문서 본문의 모든 Footnote 요소를 검색합니다.
getHeader()HeaderSection문서의 헤더 섹션이 있는 경우 검색합니다.
getId()String문서의 고유 식별자를 검색합니다.
getLanguage()String문서의 언어 코드를 가져옵니다.
getName()String문서의 제목을 검색합니다.
getNamedRangeById(id)NamedRange지정된 ID로 NamedRange를 가져옵니다.
getNamedRanges()NamedRange[]문서의 모든 NamedRange 객체를 가져옵니다.
getNamedRanges(name)NamedRange[]지정된 이름을 가진 문서의 모든 NamedRange 객체를 가져옵니다.
getSelection()Range활성 문서에서 사용자의 선택사항을 가져옵니다.
getSupportedLanguageCodes()String[]Google Docs 파일에서 지원되는 모든 언어 코드를 가져옵니다.
getUrl()String현재 문서에 액세스할 URL을 검색합니다.
getViewers()User[]Document의 뷰어 및 댓글 작성자 목록을 가져옵니다.
newPosition(element, offset)Position특정 요소를 기준으로 문서의 위치를 가리키는 새 Position를 만듭니다.
newRange()RangeBuilder문서 요소에서 Range 객체를 구성하는 데 사용되는 빌더를 만듭니다.
removeEditor(emailAddress)DocumentDocument의 편집자 목록에서 지정된 사용자를 삭제합니다.
removeEditor(user)DocumentDocument의 편집자 목록에서 지정된 사용자를 삭제합니다.
removeViewer(emailAddress)DocumentDocument의 뷰어 및 댓글 작성자 목록에서 지정된 사용자를 삭제합니다.
removeViewer(user)DocumentDocument의 뷰어 및 댓글 작성자 목록에서 지정된 사용자를 삭제합니다.
saveAndClose()void현재 Document를 저장합니다.
setCursor(position)DocumentPosition에 따라 활성 문서에서 사용자의 커서를 설정합니다.
setLanguage(languageCode)Document문서의 언어 코드를 설정합니다.
setName(name)Document문서 제목을 설정합니다.
setSelection(range)DocumentRange가 지정된 경우 활성 문서에서 사용자 선택을 설정합니다.

자세한 문서

addBookmark(position)

지정된 PositionBookmark를 추가합니다.

// 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 and adds a paragraph.
const paragraph = doc.getBody().appendParagraph('My new paragraph.');

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

// Adds a bookmark at the first character of the paragraph text.
const bookmark = doc.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

addEditor(emailAddress)

지정된 사용자를 Document의 편집자 목록에 추가합니다. 사용자가 이미 뷰어 목록에 있는 경우 이 방법은 뷰어 목록에서 사용자를 승격합니다.

매개변수

이름유형설명
emailAddressString추가할 사용자의 이메일 주소입니다.

리턴

Document: 체이닝용 Document입니다.

승인

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

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

addEditor(user)

지정된 사용자를 Document의 편집자 목록에 추가합니다. 사용자가 이미 뷰어 목록에 있는 경우 이 방법은 뷰어 목록에서 사용자를 승격합니다.

매개변수

이름유형설명
userUser추가할 사용자의 표현입니다.

리턴

Document: 체이닝용 Document입니다.

승인

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

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

addEditors(emailAddresses)

지정된 사용자 배열을 Document의 편집기 목록에 추가합니다. 이미 뷰어 목록에 있는 사용자가 있는 경우 이 메서드는 뷰어 목록에서 사용자를 승격시킵니다.

매개변수

이름유형설명
emailAddressesString[]추가할 사용자의 이메일 주소 배열입니다.

리턴

Document: 체이닝용 Document입니다.

승인

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

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

addFooter()

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

// 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');

// Adds a footer to the document.
const footer = doc.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 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');

// Adds a header to the document.
const header = doc.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 the document.
var doc = DocumentApp.getActiveDocument();
var rangeBuilder = doc.newRange();
var tables = doc.getBody().getTables();
for (var i = 0; i < tables.length; i++) {
  rangeBuilder.addElement(tables[i]);
}
doc.addNamedRange('Document tables', rangeBuilder.build());

매개변수

이름유형설명
nameString범위의 이름입니다. 고유할 필요는 없습니다. 범위 이름은 1~256자(영문 기준)여야 합니다.
rangeRange이름과 연결할 요소의 범위입니다. 범위는 활성 선택 또는 검색결과이거나 newRange()로 직접 구성할 수 있습니다.

리턴

NamedRange: NamedRange입니다.

승인

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

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

addViewer(emailAddress)

지정된 사용자를 Document의 뷰어 목록에 추가합니다. 사용자가 이미 편집자 목록에 있는 경우 이 메서드는 영향을 미치지 않습니다.

매개변수

이름유형설명
emailAddressString추가할 사용자의 이메일 주소입니다.

리턴

Document: 체이닝용 Document입니다.

승인

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

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

addViewer(user)

지정된 사용자를 Document의 뷰어 목록에 추가합니다. 사용자가 이미 편집자 목록에 있는 경우 이 메서드는 영향을 미치지 않습니다.

매개변수

이름유형설명
userUser추가할 사용자의 표현입니다.

리턴

Document: 체이닝용 Document입니다.

승인

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

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

addViewers(emailAddresses)

지정된 사용자 배열을 Document의 뷰어 목록에 추가합니다. 이미 편집자 목록에 있는 사용자가 있는 경우 이 방법은 사용자에게 영향을 미치지 않습니다.

매개변수

이름유형설명
emailAddressesString[]추가할 사용자의 이메일 주소 배열입니다.

리턴

Document: 체이닝용 Document입니다.

승인

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

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

getAs(contentType)

현재 Document 콘텐츠를 지정된 유형의 blob으로 검색합니다.

// 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 as a PDF.
const pdf = doc.getAs('application/pdf');

// Logs the name of the PDF to the console.
console.log(pdf.getName());

매개변수

이름유형설명
contentTypeString변환할 MIME 유형입니다. 현재는 'application/pdf'만 지원됩니다.

리턴

Blob - blob으로서의 현재 문서입니다.


getBlob()

현재 Document 콘텐츠를 blob으로 검색합니다.

// 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');

// Retrieves the current document's contents as a blob and logs it to the console.
console.log(doc.getBlob().getContentType());

리턴

Blob - blob으로서의 현재 문서입니다.


getBody()

활성 문서의 Body를 검색합니다.

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

Document의 요소 메서드가 활성 Body에 위임합니다.

// 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 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 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 bookmark by its ID.
const bookmark = doc.getBookmark('id.xyz654321');

// If the bookmark exists, 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 — 지정된 ID를 가진 Bookmark 또는 null 존재하지 않는 경우 Bookmark

승인

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

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

getBookmarks()

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

// Opens the Docs file by its ID. If you created your script from within
// a Google Docs file, you can use DocumentApp.getActiveDocument() instead.
const doc = DocumentApp.openById('abc123456');

// Gets all of the bookmarks in the document.
const bookmarks = doc.getBookmarks();

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

리턴

Bookmark[] - 문서에 있는 Bookmark 객체의 배열

승인

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

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

getCursor()

활성 문서에서 사용자의 커서를 가져옵니다. 스크립트는 스크립트를 실행 중인 사용자의 커서에만 액세스할 수 있으며, 스크립트가 문서에 바인딩된 경우에만 가능합니다.

// Insert some text at the cursor position and make it bold.
var cursor = DocumentApp.getActiveDocument().getCursor();
if (cursor) {
  // Attempt to insert text at the cursor position. If the insertion returns null, the cursor's
  // containing element doesn't allow insertions, so show the user an error message.
  var element = cursor.insertText('ಠ‿ಠ');
  if (element) {
    element.setBold(true);
  } else {
    DocumentApp.getUi().alert('Cannot insert text here.');
  }
} else {
  DocumentApp.getUi().alert('Cannot find a cursor.');
}

리턴

Position - 사용자의 커서 표시 또는 사용자가 문서에 커서가 없거나 스크립트가 문서에 바인딩되지 않은 경우 null

승인

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

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

getEditors()

Document의 편집자 목록을 가져옵니다.

리턴

User[] - 수정 권한이 있는 사용자의 배열입니다.

승인

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

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

getFooter()

문서의 바닥글이 있는 경우 검색합니다.

// 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 text of the document's footer and logs it to the console.
console.log(doc.getFooter().getText());

리턴

FooterSection — 문서 바닥글입니다.

승인

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

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

getFootnotes()

문서 본문의 모든 Footnote 요소를 검색합니다.

getFootnotes를 호출하면 문서 요소가 반복됩니다. 대용량 문서의 경우 이 메서드를 불필요하게 호출하지 마세요.

// 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 first footnote.
const footnote = doc.getFootnotes()[0];

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

리턴

Footnote[] — 문서 각주입니다.

승인

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

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

getHeader()

문서의 헤더 섹션이 있는 경우 검색합니다.

// 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 text of the document's header and logs it to the console.
console.log(doc.getHeader().getText());

리턴

HeaderSection - 문서 헤더입니다.

승인

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

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

getId()

문서의 고유 식별자를 검색합니다. 문서 ID는 DocumentApp.openById()와 함께 사용되어 특정 문서 인스턴스를 엽니다.

리턴

String: 문서의 ID입니다.

승인

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

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

getLanguage()

문서의 언어 코드를 가져옵니다. 이 언어는 문서 편집기의 파일 > 언어에 표시된 언어로, 문서에 포함된 실제 언어가 아닐 수도 있습니다.

리턴

String: 문서 언어 또는 정의되지 않은 경우 null입니다.

승인

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

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

getName()

문서의 제목을 검색합니다.

리턴

String — 문서 제목

승인

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

  • 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: 지정된 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

getSelection()

활성 문서에서 사용자의 선택사항을 가져옵니다. 스크립트는 스크립트를 실행 중인 사용자의 선택에 액세스할 수 있으며, 이는 문서에 결합된 경우에만 가능합니다.

// Display a dialog box that tells the user how many elements are included in the selection.
var selection = DocumentApp.getActiveDocument().getSelection();
if (selection) {
  var elements = selection.getRangeElements();
  DocumentApp.getUi().alert('Number of selected elements: ' + elements.length);
} else {
  DocumentApp.getUi().alert('Nothing is selected.');
}

리턴

Range - 사용자가 선택한 항목. 사용자가 문서에서 선택한 항목이 없는 경우, 단락의 끝만 선택되거나, 단락의 끝과 새 줄만 선택된 경우, 스크립트가 문서에 바인딩되지 않은 경우 null

승인

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

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

getSupportedLanguageCodes()

Google Docs 파일에서 지원되는 모든 언어 코드를 가져옵니다.

리턴

String[] - 언어 코드 배열입니다.

승인

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

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

getUrl()

현재 문서에 액세스할 URL을 검색합니다.

var doc = DocumentApp.getActiveDocument();

// Send out the link to open the document.
MailApp.sendEmail("<email-address>", doc.getName(), doc.getUrl());

리턴

String: 현재 문서에 액세스할 URL입니다.

승인

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

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

getViewers()

Document의 뷰어 및 댓글 작성자 목록을 가져옵니다.

리턴

User[] — 보기 또는 댓글 권한이 있는 사용자의 배열입니다.

승인

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

  • 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.
var doc = DocumentApp.getActiveDocument();
var paragraph = doc.getBody().appendParagraph('My new paragraph.');
var position = doc.newPosition(paragraph.getChild(0), 2);
doc.setCursor(position);

매개변수

이름유형설명
elementElementPosition를 포함할 요소입니다. 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 document.
var doc = DocumentApp.getActiveDocument();
var rangeBuilder = doc.newRange();
var tables = doc.getBody().getTables();
for (var 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

removeEditor(emailAddress)

Document의 편집자 목록에서 지정된 사용자를 삭제합니다. 이 메서드는 일반 액세스 권한을 가진 사용자 클래스에 속한 경우(예: Document이 사용자의 전체 도메인과 공유되었거나 Document가 사용자가 액세스할 수 있는 공유 드라이브에 있는 경우) 사용자가 Document에 액세스하는 것을 차단하지 않습니다.

Drive 파일의 경우 뷰어 목록에서도 사용자가 삭제됩니다.

매개변수

이름유형설명
emailAddressString삭제할 사용자의 이메일 주소입니다.

리턴

Document: 체이닝용 Document입니다.

승인

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

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

removeEditor(user)

Document의 편집자 목록에서 지정된 사용자를 삭제합니다. 이 메서드는 일반 액세스 권한을 가진 사용자 클래스에 속한 경우(예: Document이 사용자의 전체 도메인과 공유되었거나 Document가 사용자가 액세스할 수 있는 공유 드라이브에 있는 경우) 사용자가 Document에 액세스하는 것을 차단하지 않습니다.

Drive 파일의 경우 뷰어 목록에서도 사용자가 삭제됩니다.

매개변수

이름유형설명
userUser삭제할 사용자의 표현입니다.

리턴

Document: 체이닝용 Document입니다.

승인

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

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

removeViewer(emailAddress)

Document의 뷰어 및 댓글 작성자 목록에서 지정된 사용자를 삭제합니다. 이 메서드는 뷰어 또는 댓글 작성자가 아닌 편집자인 경우 영향을 미치지 않습니다. 이 메서드는 일반 액세스 권한을 가진 사용자 클래스에 속한 경우(예: Document이 사용자의 전체 도메인과 공유되었거나 Document가 사용자가 액세스할 수 있는 공유 드라이브에 있는 경우) 사용자가 Document에 액세스하는 것을 차단하지 않습니다.

Drive 파일의 경우 편집자 목록에서도 사용자가 삭제됩니다.

매개변수

이름유형설명
emailAddressString삭제할 사용자의 이메일 주소입니다.

리턴

Document: 체이닝용 Document입니다.

승인

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

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

removeViewer(user)

Document의 뷰어 및 댓글 작성자 목록에서 지정된 사용자를 삭제합니다. 이 메서드는 사용자가 뷰어가 아닌 편집자인 경우 영향을 미치지 않습니다. 또한 이 메서드는 일반 액세스 권한을 가진 사용자 클래스에 속한 경우(예: Document이 사용자의 전체 도메인과 공유되었거나 Document가 사용자가 액세스할 수 있는 공유 드라이브에 있는 경우) 사용자가 Document에 액세스하는 것을 차단하지 않습니다.

Drive 파일의 경우 편집자 목록에서도 사용자가 삭제됩니다.

매개변수

이름유형설명
userUser삭제할 사용자의 표현입니다.

리턴

Document: 체이닝용 Document입니다.

승인

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

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

saveAndClose()

현재 Document를 저장합니다. 대기 중인 업데이트가 플러시되고 적용됩니다.

saveAndClose() 메서드는 수정 가능한 각 Document의 스크립트 실행 종료 시 자동으로 호출됩니다.

닫힌 Document은(는) 수정할 수 없습니다. 수정할 문서를 다시 열려면 DocumentApp.openById()를 사용하세요.

승인

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

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

setCursor(position)

Position에 따라 활성 문서에서 사용자의 커서를 설정합니다. 스크립트는 스크립트를 실행 중인 사용자의 커서에만 액세스할 수 있으며, 스크립트가 문서에 바인딩된 경우에만 가능합니다.

// Append a paragraph, then place the user's cursor after the first word of the new paragraph.
var doc = DocumentApp.getActiveDocument();
var paragraph = doc.getBody().appendParagraph('My new paragraph.');
var position = doc.newPosition(paragraph.getChild(0), 2);
doc.setCursor(position);

매개변수

이름유형설명
positionPosition새 커서 위치

리턴

Document — 체이닝용 Document

승인

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

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

setLanguage(languageCode)

문서의 언어 코드를 설정합니다. 이 언어는 문서 편집기의 파일 > 언어에 표시된 언어로, 문서에 포함된 실제 언어가 아닐 수도 있습니다. getSupportedLanguageCodes()를 사용하여 유효한 언어 코드를 모두 가져옵니다.

매개변수

이름유형설명
languageCodeString언어 코드입니다.

리턴

Document: 체이닝용 Document입니다.

승인

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

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

setName(name)

문서 제목을 설정합니다.

매개변수

이름유형설명
nameString새 문서 제목

리턴

Document — 현재 문서

승인

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

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

setSelection(range)

Range가 지정된 경우 활성 문서에서 사용자 선택을 설정합니다. 스크립트는 스크립트를 실행 중인 사용자의 선택에만 액세스할 수 있습니다. 단, 스크립트가 문서에 결합된 경우에만 가능합니다.

// Change the user's selection to a range that includes every table in the document.
var doc = DocumentApp.getActiveDocument();
var rangeBuilder = doc.newRange();
var tables = doc.getBody().getTables();
for (var i = 0; i < tables.length; i++) {
  rangeBuilder.addElement(tables[i]);
}
doc.setSelection(rangeBuilder.build());

매개변수

이름유형설명
rangeRange선택할 새 요소 범위

리턴

Document — 체이닝용 Document

승인

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

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