서식 있는 텍스트와 표, 목록 등의 요소가 포함된 문서
DocumentApp
을(를) 사용하여 문서를 열거나 만들 수 있습니다.
// Open a document by ID. var doc = DocumentApp.openById("<my-id>"); // Create and open a document. doc = DocumentApp.create("Document Title");
방법
자세한 문서
addBookmark(position)
지정된 Position
에 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. // 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()); }
매개변수
이름 | 유형 | 설명 |
---|---|---|
position | Position | 새 북마크의 위치입니다. |
리턴
Bookmark
- 새 북마크입니다.
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
addEditor(emailAddress)
지정된 사용자를 Document
의 편집자 목록에 추가합니다. 사용자가 이미 뷰어 목록에 있는 경우 이 메서드는 사용자를 뷰어 목록에서 제거할 수 있습니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
emailAddress | String | 추가할 사용자의 이메일 주소입니다. |
리턴
Document
: 체이닝을 위한 Document
입니다.
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
addEditor(user)
addEditors(emailAddresses)
지정된 사용자 배열을 Document
의 편집자 목록에 추가합니다. 사용자가 이미 뷰어 목록에 있다면 이 메서드는 해당 사용자를 뷰어 목록 밖으로 승격시킵니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
emailAddresses | String[] | 추가할 사용자의 이메일 주소 배열입니다. |
리턴
Document
: 체이닝을 위한 Document
입니다.
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
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가 있는 Range
인 NamedRange
를 추가합니다. 이름이 반드시 고유하지는 않습니다. 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());
매개변수
이름 | 유형 | 설명 |
---|---|---|
name | String | 범위 이름으로, 고유하지 않아도 됩니다. 범위 이름은 1~256자(영문 기준)여야 합니다. |
range | Range | 이름과 연결할 요소의 범위입니다. 범위는 활성 선택 항목 또는 검색결과이거나 newRange() 를 사용하여 수동으로 구성할 수 있습니다. |
리턴
NamedRange
- NamedRange
입니다.
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
addViewer(emailAddress)
지정된 사용자를 Document
의 뷰어 목록에 추가합니다. 사용자가 이미 편집자 목록에 있었다면 이 메서드는 아무런 영향을 미치지 않습니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
emailAddress | String | 추가할 사용자의 이메일 주소입니다. |
리턴
Document
: 체이닝을 위한 Document
입니다.
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
addViewer(user)
addViewers(emailAddresses)
지정된 사용자 배열을 Document
의 뷰어 목록에 추가합니다. 사용자가 이미 편집자 목록에 있다면 이 메서드는 영향을 미치지 않습니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
emailAddresses | String[] | 추가할 사용자의 이메일 주소 배열입니다. |
리턴
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());
매개변수
이름 | 유형 | 설명 |
---|---|---|
contentType | String | 변환할 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.'); }
매개변수
이름 | 유형 | 설명 |
---|---|---|
id | String | Bookmark 의 ID입니다. |
리턴
Bookmark
- 지정된 ID가 있는 Bookmark
이거나 이러한 Bookmark
가 없는 경우 null
입니다.
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
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()
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처럼 문서 내에서 고유합니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
id | String | 문서 내에서 고유한 범위의 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
에 액세스할 수 있습니다. 스크립트 간의 의도하지 않은 충돌을 방지하려면 범위 이름 앞에 고유 문자열을 붙이는 것이 좋습니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
name | String | 범위 이름(반드시 고유하지는 않음) |
리턴
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()
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);
매개변수
이름 | 유형 | 설명 |
---|---|---|
element | Element | 새 Position 를 포함할 요소. Text 요소 또는 Paragraph 와 같은 컨테이너 요소여야 합니다. |
offset | Integer | Text 요소의 경우 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 파일의 경우 뷰어 목록에서도 사용자가 삭제됩니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
emailAddress | String | 삭제할 사용자의 이메일 주소입니다. |
리턴
Document
: 체이닝을 위한 Document
입니다.
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
removeEditor(user)
지정된 사용자를 Document
의 편집자 목록에서 삭제합니다. 일반 액세스 권한이 있는 사용자 클래스에 속한 경우(예: Document
가 사용자의 전체 도메인과 공유되거나 Document
가 사용자가 액세스할 수 있는 공유 드라이브에 있는 경우) 이 메서드는 사용자가 Document
에 액세스하는 것을 차단하지 않습니다.
Drive 파일의 경우 뷰어 목록에서도 사용자가 삭제됩니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
user | User | 삭제할 사용자의 표현입니다. |
리턴
Document
: 체이닝을 위한 Document
입니다.
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
removeViewer(emailAddress)
Document
의 뷰어 및 댓글 작성자 목록에서 지정된 사용자를 삭제합니다. 사용자가 뷰어나 댓글 작성자가 아닌 편집자인 경우에는 이 메서드가 영향을 미치지 않습니다. 또한 이 메서드는 일반 액세스 권한이 있는 사용자 클래스에 속한 경우(예: Document
가 사용자의 전체 도메인과 공유되거나 Document
가 사용자가 액세스할 수 있는 공유 드라이브에 있는 경우) Document
에 액세스하는 것을 차단하지 않습니다.
Drive 파일의 경우 편집자 목록에서도 사용자가 삭제됩니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
emailAddress | String | 삭제할 사용자의 이메일 주소입니다. |
리턴
Document
: 체이닝을 위한 Document
입니다.
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
removeViewer(user)
Document
의 뷰어 및 댓글 작성자 목록에서 지정된 사용자를 삭제합니다. 사용자가 뷰어가 아닌 편집자인 경우에는 이 메서드가 영향을 미치지 않습니다. 또한 이 메서드는 일반 액세스 권한이 있는 사용자 클래스에 속한 경우(예: Document
가 사용자의 전체 도메인과 공유되거나 Document
가 사용자가 액세스할 수 있는 공유 드라이브에 있는 경우) Document
에 액세스하는 것을 차단하지 않습니다.
Drive 파일의 경우 편집자 목록에서도 사용자가 삭제됩니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
user | User | 삭제할 사용자의 표현입니다. |
리턴
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);
매개변수
이름 | 유형 | 설명 |
---|---|---|
position | Position | 새 커서 위치 |
리턴
Document
: 이 Document
, 체이닝용
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setLanguage(languageCode)
문서의 언어 코드를 설정합니다. 문서 편집기의 파일 > 언어에 표시되는 언어이며 문서에 포함된 실제 언어가 아닐 수도 있습니다. getSupportedLanguageCodes()
를 사용하여 유효한 모든 언어 코드를 가져옵니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
languageCode | String | 언어 코드입니다. |
리턴
Document
: 체이닝을 위한 Document
입니다.
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setName(name)
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());
매개변수
이름 | 유형 | 설명 |
---|---|---|
range | Range | 선택할 새 요소 범위 |
리턴
Document
: 이 Document
, 체이닝용
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents