Một phần tử đại diện cho một đoạn văn. Paragraph
có thể chứa các phần tử Equation
, Footnote
, HorizontalRule
, InlineDrawing
, InlineImage
, PageBreak
và Text
. Để biết thêm thông tin về cấu trúc tài liệu, hãy xem hướng dẫn mở rộng Google Tài liệu.
Paragraphs
không được chứa ký tự dòng mới. Ký tự dòng mới ("\n") được chuyển đổi thành ký tự ngắt dòng ("\r").
var body = DocumentApp.getActiveDocument().getBody(); // Append a document header paragraph. var header = body.appendParagraph("A Document"); header.setHeading(DocumentApp.ParagraphHeading.HEADING1); // Append a section header paragraph. var section = body.appendParagraph("Section 1"); section.setHeading(DocumentApp.ParagraphHeading.HEADING2); // Append a regular paragraph. body.appendParagraph("This is a typical paragraph.");
Phương thức
Phương thức | Loại dữ liệu trả về | Mô tả ngắn |
---|---|---|
addPositionedImage(image) | PositionedImage | Tạo và chèn một PositionedImage mới từ blob hình ảnh chỉ định. |
appendHorizontalRule() | HorizontalRule | Tạo và thêm HorizontalRule mới. |
appendInlineImage(image) | InlineImage | Tạo và thêm một InlineImage mới từ blob hình ảnh chỉ định. |
appendInlineImage(image) | InlineImage | Thêm InlineImage đã cho. |
appendPageBreak() | PageBreak | Tạo và thêm PageBreak mới. |
appendPageBreak(pageBreak) | PageBreak | Thêm PageBreak đã cho. |
appendText(text) | Text | Tạo và thêm phần tử Text mới với nội dung được chỉ định. |
appendText(text) | Text | Thêm phần tử Text đã cho. |
clear() | Paragraph | Xóa nội dung của phần tử. |
copy() | Paragraph | Trả về bản sao sâu, tách rời của phần tử hiện tại. |
editAsText() | Text | Lấy phiên bản Text của phần tử hiện tại để chỉnh sửa. |
findElement(elementType) | RangeElement | Tìm kiếm nội dung của phần tử cho thành phần con thuộc loại đã chỉ định. |
findElement(elementType, from) | RangeElement | Tìm kiếm nội dung của phần tử cho thành phần con thuộc loại đã chỉ định, bắt đầu từ RangeElement được chỉ định. |
findText(searchPattern) | RangeElement | Tìm kiếm nội dung của phần tử cho mẫu văn bản đã chỉ định bằng biểu thức chính quy. |
findText(searchPattern, from) | RangeElement | Tìm kiếm nội dung của phần tử cho mẫu văn bản đã chỉ định, bắt đầu từ kết quả tìm kiếm nhất định. |
getAlignment() | HorizontalAlignment | Truy xuất HorizontalAlignment . |
getAttributes() | Object | Truy xuất các thuộc tính của phần tử. |
getChild(childIndex) | Element | Truy xuất phần tử con tại chỉ mục con đã chỉ định. |
getChildIndex(child) | Integer | Truy xuất chỉ mục con cho phần tử con đã chỉ định. |
getHeading() | ParagraphHeading | Truy xuất ParagraphHeading . |
getIndentEnd() | Number | Truy lục thụt lề cuối đoạn, tính theo điểm. |
getIndentFirstLine() | Number | Truy xuất thụt lề dòng đầu tiên, theo điểm. |
getIndentStart() | Number | Truy xuất thụt lề đầu đoạn. |
getLineSpacing() | Number | Truy xuất khoảng cách dòng, tính bằng điểm. |
getLinkUrl() | String | Truy xuất url liên kết. |
getNextSibling() | Element | Truy xuất phần tử phụ tiếp theo của phần tử. |
getNumChildren() | Integer | Truy xuất số lượng tệp con. |
getParent() | ContainerElement | Truy xuất phần tử mẹ của phần tử. |
getPositionedImage(id) | PositionedImage | Nhận PositionedImage theo mã nhận dạng của hình ảnh. |
getPositionedImages() | PositionedImage[] | Lấy tất cả đối tượng PositionedImage liên kết với đoạn. |
getPreviousSibling() | Element | Truy xuất phần tử đồng cấp trước đó của phần tử. |
getSpacingAfter() | Number | Truy xuất khoảng cách sau phần tử, tính bằng điểm. |
getSpacingBefore() | Number | Truy xuất khoảng cách trước phần tử, tính bằng điểm. |
getText() | String | Truy xuất nội dung của phần tử dưới dạng chuỗi văn bản. |
getTextAlignment() | TextAlignment | Xem cách căn chỉnh văn bản. |
getType() | ElementType | Truy xuất ElementType của phần tử. |
insertHorizontalRule(childIndex) | HorizontalRule | Tạo và chèn một HorizontalRule vào chỉ mục đã chỉ định. |
insertInlineImage(childIndex, image) | InlineImage | Tạo và chèn một InlineImage mới từ blob hình ảnh đã chỉ định, tại chỉ mục được chỉ định. |
insertInlineImage(childIndex, image) | InlineImage | Chèn InlineImage đã cho tại chỉ mục được chỉ định. |
insertPageBreak(childIndex) | PageBreak | Tạo và chèn một PageBreak mới vào chỉ mục đã chỉ định. |
insertPageBreak(childIndex, pageBreak) | PageBreak | Chèn PageBreak đã cho tại chỉ mục được chỉ định. |
insertText(childIndex, text) | Text | Tạo và chèn một phần tử văn bản mới tại chỉ mục được chỉ định. |
insertText(childIndex, text) | Text | Chèn phần tử Text đã cho vào chỉ mục đã chỉ định, với nội dung văn bản đã chỉ định. |
isAtDocumentEnd() | Boolean | Xác định xem phần tử có ở cuối Document hay không. |
isLeftToRight() | Boolean | Truy xuất cài đặt từ trái sang phải. |
merge() | Paragraph | Hợp nhất phần tử này với thành phần cùng loại trước đó cùng loại. |
removeChild(child) | Paragraph | Xoá phần tử con đã chỉ định. |
removeFromParent() | Paragraph | Xóa phần tử khỏi phần tử mẹ. |
removePositionedImage(id) | Boolean | Xoá PositionedImage theo mã nhận dạng của hình ảnh. |
replaceText(searchPattern, replacement) | Element | Thay thế tất cả các lần xuất hiện của một mẫu văn bản bằng một chuỗi thay thế nhất định, sử dụng các biểu thức chính quy. |
setAlignment(alignment) | Paragraph | Đặt HorizontalAlignment . |
setAttributes(attributes) | Paragraph | Đặt thuộc tính của phần tử. |
setHeading(heading) | Paragraph | Đặt ParagraphHeading . |
setIndentEnd(indentEnd) | Paragraph | Đặt thụt lề cuối, theo điểm. |
setIndentFirstLine(indentFirstLine) | Paragraph | Đặt thụt lề dòng đầu tiên, theo điểm. |
setIndentStart(indentStart) | Paragraph | Đặt thụt lề đầu đoạn, tính theo điểm. |
setLeftToRight(leftToRight) | Paragraph | Đặt cài đặt từ trái sang phải. |
setLineSpacing(multiplier) | Paragraph | Đặt khoảng cách dòng làm đại lượng cho biết số dòng cần sử dụng để giãn cách. |
setLinkUrl(url) | Paragraph | Đặt url liên kết. |
setSpacingAfter(spacingAfter) | Paragraph | Đặt khoảng cách sau phần tử, tính bằng điểm. |
setSpacingBefore(spacingBefore) | Paragraph | Đặt khoảng cách trước phần tử, theo điểm. |
setText(text) | void | Đặt nội dung của đoạn văn bản dưới dạng văn bản. |
setTextAlignment(textAlignment) | Paragraph | Đặt căn chỉnh văn bản. |
Tài liệu chi tiết
addPositionedImage(image)
Tạo và chèn một PositionedImage
mới từ blob hình ảnh chỉ định.
// 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 paragraph from the body. const paragraph = body.getParagraphs()[0]; // Fetches the specified image URL. const image = UrlFetchApp.fetch('https://fonts.gstatic.com/s/i/productlogos/apps_script/v10/web-24dp/logo_apps_script_color_1x_web_24dp.png'); // Adds the image to the document, anchored to the first paragraph. paragraph.addPositionedImage(image);
Thông số
Tên | Loại | Mô tả |
---|---|---|
image | BlobSource | Dữ liệu hình ảnh. |
Hai chiều
PositionedImage
— Hình ảnh được định vị mới.
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
appendHorizontalRule()
Tạo và thêm HorizontalRule
mới.
// 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 paragraph from the body. const paragraph = body.getParagraphs()[0]; // Adds a horizontal line under the first paragraph. paragraph.appendHorizontalRule();
Hai chiều
HorizontalRule
— Quy tắc ngang mới.
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
appendInlineImage(image)
Tạo và thêm một InlineImage
mới từ blob hình ảnh chỉ định.
// 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 paragraph from the body. const paragraph = body.getParagraphs()[0]; // Fetches the image from the specified image URL. const image = UrlFetchApp .fetch('https://fonts.gstatic.com/s/i/productlogos/apps_script/v10/web-96dp/logo_apps_script_color_1x_web_96dp.png'); // Adds the image to the first paragraph. paragraph.appendInlineImage(image);
Thông số
Tên | Loại | Mô tả |
---|---|---|
image | BlobSource | Dữ liệu hình ảnh. |
Hai chiều
InlineImage
— Hình ảnh đã thêm.
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
appendInlineImage(image)
Thêm InlineImage
đã cho.
// 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 paragraph from the body. const paragraph = body.getParagraphs()[0]; // Makes a copy of the first image in the body. const image = body.getImages()[0].copy();; // Adds the image to the first paragraph. paragraph.appendInlineImage(image);
Thông số
Tên | Loại | Mô tả |
---|---|---|
image | InlineImage | Dữ liệu hình ảnh. |
Hai chiều
InlineImage
— Hình ảnh đã thêm.
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
appendPageBreak()
Tạo và thêm PageBreak
mới.
Lưu ý: PageBreaks
có thể không nằm trong TableCells
.
Nếu phần tử hiện tại có trong ô bảng, ngoại lệ sẽ được gửi.
// 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 paragraph from the body. const paragraph = body.getParagraphs()[0]; // Adds a page break after the first paragraph. paragraph.appendPageBreak();
Hai chiều
PageBreak
— Phần tử ngắt trang mới.
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
appendPageBreak(pageBreak)
Thêm PageBreak
đã cho.
Lưu ý: Không thể chứa PageBreaks
trong TableCells
.
Nếu phần tử hiện tại tồn tại trong ô trong bảng, tập lệnh sẽ gửi một ngoại lệ.
// 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 paragraph from the body. const paragraph = body.getParagraphs()[0]; // Adds a page break after the first paragraph. const pageBreak = paragraph.appendPageBreak(); // Makes a copy of the page break. const newPageBreak = pageBreak.copy(); // Adds the copied page break to the paragraph. paragraph.appendPageBreak(newPageBreak);
Thông số
Tên | Loại | Mô tả |
---|---|---|
pageBreak | PageBreak | Ngắt trang để thêm. |
Hai chiều
PageBreak
— Phần tử ngắt trang được thêm vào.
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
appendText(text)
Tạo và thêm phần tử Text
mới với nội dung được chỉ định.
// 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 paragraph from the body. const paragraph = body.getParagraphs()[0]; // Adds a string to the paragraph. paragraph.appendText('This is a new sentence.');
Thông số
Tên | Loại | Mô tả |
---|---|---|
text | String | Nội dung văn bản. |
Hai chiều
Text
— Phần tử văn bản mới.
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
appendText(text)
Thêm phần tử Text
đã cho.
// 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 text from the first paragraph in the body. const paragraph1 = body.getParagraphs()[0]; const text = paragraph1.getText(); // Gets the third paragraph in the body. const paragraph3 = body.getParagraphs()[2]; // Adds the text from the first paragraph to the third paragraph. paragraph3.appendText(text);
Thông số
Tên | Loại | Mô tả |
---|---|---|
text | Text | Phần tử văn bản cần kết hợp. |
Hai chiều
Text
— Phần tử văn bản đã thêm.
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
clear()
copy()
Trả về bản sao sâu, tách rời của phần tử hiện tại.
Mọi phần tử con có trong phần tử này cũng được sao chép. Phần tử mới không có thành phần mẹ.
Hai chiều
Paragraph
— Bản sao mới.
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
editAsText()
Lấy phiên bản Text
của phần tử hiện tại để chỉnh sửa.
Sử dụng editAsText
để thao tác với nội dung phần tử dưới dạng văn bản đa dạng thức. Chế độ editAsText
bỏ qua các phần tử phi văn bản (chẳng hạn như InlineImage
và HorizontalRule
).
Các phần tử con nằm hoàn toàn trong một phạm vi văn bản đã xóa sẽ bị xóa khỏi phần tử.
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);
Hai chiều
Text
— phiên bản văn bản của phần tử hiện tại
findElement(elementType)
Tìm kiếm nội dung của phần tử cho thành phần con thuộc loại đã chỉ định.
Thông số
Tên | Loại | Mô tả |
---|---|---|
elementType | ElementType | loại phần tử cần tìm kiếm |
Hai chiều
RangeElement
— kết quả tìm kiếm cho biết vị trí của phần tử tìm kiếm
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
findElement(elementType, from)
Tìm kiếm nội dung của phần tử cho thành phần con thuộc loại đã chỉ định, bắt đầu từ RangeElement
được chỉ định.
// 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; } }
Thông số
Tên | Loại | Mô tả |
---|---|---|
elementType | ElementType | loại phần tử cần tìm kiếm |
from | RangeElement | kết quả tìm kiếm để tìm kiếm |
Hai chiều
RangeElement
— kết quả tìm kiếm cho biết vị trí tiếp theo của phần tử tìm kiếm
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
findText(searchPattern)
Tìm kiếm nội dung của phần tử cho mẫu văn bản đã chỉ định bằng biểu thức chính quy.
Một số tính năng biểu thức chính quy JavaScript không được hỗ trợ đầy đủ, chẳng hạn như các nhóm thu thập và công cụ sửa đổi chế độ.
Mẫu cụm từ thông dụng đã cho được so khớp độc lập với từng khối văn bản có trong phần tử hiện tại.
Thông số
Tên | Loại | Mô tả |
---|---|---|
searchPattern | String | mẫu cần tìm kiếm |
Hai chiều
RangeElement
– kết quả tìm kiếm cho biết vị trí của văn bản tìm kiếm hoặc rỗng nếu không có kết quả trùng khớp
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
findText(searchPattern, from)
Tìm kiếm nội dung của phần tử cho mẫu văn bản đã chỉ định, bắt đầu từ kết quả tìm kiếm nhất định.
Một số tính năng biểu thức chính quy JavaScript không được hỗ trợ đầy đủ, chẳng hạn như các nhóm thu thập và công cụ sửa đổi chế độ.
Mẫu cụm từ thông dụng đã cho được so khớp độc lập với từng khối văn bản có trong phần tử hiện tại.
Thông số
Tên | Loại | Mô tả |
---|---|---|
searchPattern | String | mẫu cần tìm kiếm |
from | RangeElement | kết quả tìm kiếm để tìm kiếm |
Hai chiều
RangeElement
– một kết quả tìm kiếm cho biết vị trí tiếp theo của văn bản tìm kiếm hoặc rỗng nếu không có kết quả trùng khớp
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getAlignment()
Truy xuất HorizontalAlignment
.
// 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 paragraph from the body. const paragraph = body.getParagraphs()[0]; // Sets the horizontal alignment to left for the first paragraph. paragraph.setAlignment(DocumentApp.HorizontalAlignment.LEFT); // Gets the horizontal alignment of the first paragraph and logs it to the console. console.log(paragraph.getAlignment().toString());
Hai chiều
HorizontalAlignment
– Căn chỉnh.
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getAttributes()
Truy xuất các thuộc tính của phần tử.
Kết quả là một đối tượng chứa một thuộc tính cho mỗi thuộc tính phần tử hợp lệ, trong đó mỗi tên thuộc tính tương ứng với một mục trong bảng liệt kê 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]); }
Hai chiều
Object
– Thuộc tính của phần tử.
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getChild(childIndex)
Truy xuất phần tử con tại chỉ mục con đã chỉ định.
// 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."); }
Thông số
Tên | Loại | Mô tả |
---|---|---|
childIndex | Integer | chỉ mục của phần tử con cần truy xuất |
Hai chiều
Element
— phần tử con tại chỉ mục được chỉ định
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getChildIndex(child)
Truy xuất chỉ mục con cho phần tử con đã chỉ định.
Thông số
Tên | Loại | Mô tả |
---|---|---|
child | Element | phần tử con để truy xuất chỉ mục |
Hai chiều
Integer
— chỉ mục con
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getHeading()
Truy xuất ParagraphHeading
.
// 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(); // Adds a paragraph to the body. const paragraph = body.appendParagraph('Title heading'); // Sets the paragraph heading style to 'Title.' paragraph.setHeading(DocumentApp.ParagraphHeading.TITLE); // Gets the heading style and logs it to the console. console.log(paragraph.getHeading().toString());
Hai chiều
ParagraphHeading
— Tiêu đề.
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getIndentEnd()
Truy lục thụt lề cuối đoạn, tính theo điểm.
Hai chiều
Number
— thụt lề cuối, theo điểm
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getIndentFirstLine()
Truy xuất thụt lề dòng đầu tiên, theo điểm.
Hai chiều
Number
— thụt lề dòng đầu tiên, tính bằng điểm
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getIndentStart()
Truy xuất thụt lề đầu đoạn.
Hai chiều
Number
— thụt lề đầu đoạn
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getLineSpacing()
Truy xuất khoảng cách dòng, tính bằng điểm.
Hai chiều
Number
— khoảng cách dòng, tính bằng điểm
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getLinkUrl()
Truy xuất url liên kết.
Hai chiều
String
— url liên kết hoặc rỗng nếu phần tử chứa nhiều giá trị cho thuộc tính này
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getNextSibling()
Truy xuất phần tử phụ tiếp theo của phần tử.
Thành phần phụ khác tiếp theo có cùng thành phần mẹ và theo sau thành phần hiện tại.
Hai chiều
Element
– Phần tử phụ tiếp theo.
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getNumChildren()
Truy xuất số lượng tệp con.
// 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.");
Hai chiều
Integer
— số lượng trẻ
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getParent()
Truy xuất phần tử mẹ của phần tử.
Phần tử mẹ chứa phần tử hiện tại.
Hai chiều
ContainerElement
– Phần tử mẹ.
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getPositionedImage(id)
Nhận PositionedImage
theo mã nhận dạng của hình ảnh.
Thông số
Tên | Loại | Mô tả |
---|---|---|
id | String | id hình ảnh |
Hai chiều
PositionedImage
— hình ảnh định vị
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getPositionedImages()
Lấy tất cả đối tượng PositionedImage
liên kết với đoạn.
Hai chiều
PositionedImage[]
— danh sách hình ảnh định vị
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getPreviousSibling()
Truy xuất phần tử đồng cấp trước đó của phần tử.
Các thành phần phụ khác trước có cùng thành phần mẹ và đứng trước thành phần hiện tại.
Hai chiều
Element
— Phần tử phụ trước đó.
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getSpacingAfter()
Truy xuất khoảng cách sau phần tử, tính bằng điểm.
Hai chiều
Number
— khoảng cách sau phần tử, tính bằng điểm
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getSpacingBefore()
Truy xuất khoảng cách trước phần tử, tính bằng điểm.
Hai chiều
Number
— khoảng cách trước phần tử, tính bằng điểm
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getText()
Truy xuất nội dung của phần tử dưới dạng chuỗi văn bản.
Hai chiều
String
– nội dung của phần tử dưới dạng chuỗi văn bản
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getTextAlignment()
Xem cách căn chỉnh văn bản. Các kiểu căn chỉnh có sẵn là DocumentApp.TextAlignment.NORMAL
, DocumentApp.TextAlignment.SUBSCRIPT
và DocumentApp.TextAlignment.SUPERSCRIPT
.
Hai chiều
TextAlignment
– kiểu căn chỉnh văn bản hoặc null
nếu văn bản chứa nhiều kiểu căn chỉnh văn bản hoặc nếu văn bản chưa được đặt
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getType()
Truy xuất ElementType
của phần tử.
Sử dụng getType()
để xác định loại chính xác của một phần tử nhất định.
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.'); }
Hai chiều
ElementType
— Loại phần tử.
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
insertHorizontalRule(childIndex)
Tạo và chèn một HorizontalRule
vào chỉ mục đã chỉ định.
Thông số
Tên | Loại | Mô tả |
---|---|---|
childIndex | Integer | chỉ mục để chèn phần tử |
Hai chiều
HorizontalRule
— phần tử quy tắc ngang mới
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
insertInlineImage(childIndex, image)
Tạo và chèn một InlineImage
mới từ blob hình ảnh đã chỉ định, tại chỉ mục được chỉ định.
Thông số
Tên | Loại | Mô tả |
---|---|---|
childIndex | Integer | chỉ mục để chèn phần tử |
image | BlobSource | dữ liệu hình ảnh |
Hai chiều
InlineImage
— thành phần hình ảnh cùng dòng được chèn
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
insertInlineImage(childIndex, image)
Chèn InlineImage
đã cho tại chỉ mục được chỉ định.
Thông số
Tên | Loại | Mô tả |
---|---|---|
childIndex | Integer | chỉ mục để chèn phần tử |
image | InlineImage | dữ liệu hình ảnh |
Hai chiều
InlineImage
— thành phần hình ảnh cùng dòng được chèn
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
insertPageBreak(childIndex)
Tạo và chèn một PageBreak
mới vào chỉ mục đã chỉ định.
Lưu ý: PageBreaks
có thể không nằm trong TableCells
.
Nếu phần tử hiện tại có trong ô bảng, ngoại lệ sẽ được gửi.
Thông số
Tên | Loại | Mô tả |
---|---|---|
childIndex | Integer | chỉ mục để chèn phần tử |
Hai chiều
PageBreak
— phần tử ngắt trang mới
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
insertPageBreak(childIndex, pageBreak)
Chèn PageBreak
đã cho tại chỉ mục được chỉ định.
Lưu ý: PageBreaks
có thể không nằm trong TableCells
.
Nếu phần tử hiện tại có trong ô bảng, ngoại lệ sẽ được gửi.
Thông số
Tên | Loại | Mô tả |
---|---|---|
childIndex | Integer | chỉ mục để chèn phần tử |
pageBreak | PageBreak | p[ngắt quãng để chèn |
Hai chiều
PageBreak
— phần tử ngắt trang được chèn
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
insertText(childIndex, text)
Tạo và chèn một phần tử văn bản mới tại chỉ mục được chỉ định.
Thông số
Tên | Loại | Mô tả |
---|---|---|
childIndex | Integer | chỉ mục để chèn phần tử |
text | String | nội dung văn bản |
Hai chiều
Text
— thành phần văn bản mới
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
insertText(childIndex, text)
Chèn phần tử Text
đã cho vào chỉ mục đã chỉ định, với nội dung văn bản đã chỉ định.
Thông số
Tên | Loại | Mô tả |
---|---|---|
childIndex | Integer | chỉ mục để chèn phần tử |
text | Text | thành phần văn bản cần chèn |
Hai chiều
Text
— thành phần văn bản được chèn
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
isAtDocumentEnd()
Xác định xem phần tử có ở cuối Document
hay không.
Hai chiều
Boolean
– Liệu phần tử có ở cuối tài liệu hay không.
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
isLeftToRight()
Truy xuất cài đặt từ trái sang phải.
Hai chiều
Boolean
— chế độ cài đặt từ trái sang phải
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
merge()
Hợp nhất phần tử này với thành phần cùng loại trước đó cùng loại.
Chỉ có thể hợp nhất các phần tử có cùng ElementType
. Mọi phần tử con có trong phần tử hiện tại đều sẽ được chuyển sang phần tử đồng cấp trước đó.
Phần tử hiện tại sẽ bị xóa khỏi tài liệu.
var body = DocumentApp.getActiveDocument().getBody(); // Example 1: Merge paragraphs // Append two paragraphs to the document. 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();
Hai chiều
Paragraph
— Phần tử đã hợp nhất.
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
removeChild(child)
Xoá phần tử con đã chỉ định.
Thông số
Tên | Loại | Mô tả |
---|---|---|
child | Element | phần tử con cần xóa |
Hai chiều
Paragraph
— phần tử hiện tại
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
removeFromParent()
Xóa phần tử khỏi phần tử mẹ.
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(); }
Hai chiều
Paragraph
– Phần tử đã bị xoá.
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
removePositionedImage(id)
Xoá PositionedImage
theo mã nhận dạng của hình ảnh.
Thông số
Tên | Loại | Mô tả |
---|---|---|
id | String | id hình ảnh |
Hai chiều
Boolean
— cho dù hình ảnh đã chỉ định có bị xóa hay không
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
replaceText(searchPattern, replacement)
Thay thế tất cả các lần xuất hiện của một mẫu văn bản bằng một chuỗi thay thế nhất định, sử dụng các biểu thức chính quy.
Mẫu tìm kiếm được chuyển dưới dạng chuỗi, không phải đối tượng biểu thức chính quy JavaScript. Do đó, bạn sẽ cần phải thoát mọi dấu gạch chéo ngược trong mẫu.
Các phương thức này sử dụng thư viện biểu thức chính quy RE2 của Google để hạn chế cú pháp được hỗ trợ.
Mẫu cụm từ thông dụng đã cho được so khớp độc lập với từng khối văn bản có trong phần tử hiện tại.
var body = DocumentApp.getActiveDocument().getBody(); // Clear the text surrounding "Apps Script", with or without text. body.replaceText("^.*Apps ?Script.*$", "Apps Script");
Thông số
Tên | Loại | Mô tả |
---|---|---|
searchPattern | String | mẫu regex để tìm kiếm |
replacement | String | văn bản để sử dụng thay thế |
Hai chiều
Element
— phần tử hiện tại
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setAlignment(alignment)
Đặt HorizontalAlignment
.
Thông số
Tên | Loại | Mô tả |
---|---|---|
alignment | HorizontalAlignment | căn chỉnh theo chiều ngang |
Hai chiều
Paragraph
— phần tử hiện tại
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setAttributes(attributes)
Đặt thuộc tính của phần tử.
Tham số thuộc tính được chỉ định phải là một đối tượng, trong đó mỗi tên thuộc tính là một mục trong bảng liệt kê DocumentApp.Attribute
và mỗi giá trị thuộc tính là giá trị mới cần áp dụng.
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);
Thông số
Tên | Loại | Mô tả |
---|---|---|
attributes | Object | Thuộc tính của phần tử. |
Hai chiều
Paragraph
— Phần tử hiện tại.
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setHeading(heading)
Đặt ParagraphHeading
.
Thông số
Tên | Loại | Mô tả |
---|---|---|
heading | ParagraphHeading | tiêu đề |
Hai chiều
Paragraph
— phần tử hiện tại
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setIndentEnd(indentEnd)
Đặt thụt lề cuối, theo điểm.
Thông số
Tên | Loại | Mô tả |
---|---|---|
indentEnd | Number | thụt lề cuối đoạn, tính theo điểm |
Hai chiều
Paragraph
— phần tử hiện tại
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setIndentFirstLine(indentFirstLine)
Đặt thụt lề dòng đầu tiên, theo điểm.
Thông số
Tên | Loại | Mô tả |
---|---|---|
indentFirstLine | Number | thụt lề dòng đầu tiên, tính bằng điểm |
Hai chiều
Paragraph
— phần tử hiện tại
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setIndentStart(indentStart)
Đặt thụt lề đầu đoạn, tính theo điểm.
Thông số
Tên | Loại | Mô tả |
---|---|---|
indentStart | Number | thụt lề đầu đoạn, theo điểm |
Hai chiều
Paragraph
— phần tử hiện tại
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setLeftToRight(leftToRight)
Đặt cài đặt từ trái sang phải.
Thông số
Tên | Loại | Mô tả |
---|---|---|
leftToRight | Boolean | cài đặt từ trái sang phải |
Hai chiều
Paragraph
— phần tử hiện tại
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setLineSpacing(multiplier)
Đặt khoảng cách dòng làm đại lượng cho biết số dòng cần sử dụng để giãn cách.
Thông số
Tên | Loại | Mô tả |
---|---|---|
multiplier | Number | số dòng |
Hai chiều
Paragraph
— phần tử hiện tại
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setLinkUrl(url)
setSpacingAfter(spacingAfter)
Đặt khoảng cách sau phần tử, tính bằng điểm.
Thông số
Tên | Loại | Mô tả |
---|---|---|
spacingAfter | Number | khoảng cách giữa các thành phần, tại các điểm |
Hai chiều
Paragraph
— phần tử hiện tại
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setSpacingBefore(spacingBefore)
Đặt khoảng cách trước phần tử, theo điểm.
Thông số
Tên | Loại | Mô tả |
---|---|---|
spacingBefore | Number | giãn cách trước thành phần, tại các điểm |
Hai chiều
Paragraph
— phần tử hiện tại
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setText(text)
Đặt nội dung của đoạn văn bản dưới dạng văn bản.
Lưu ý: nội dung hiện có sẽ bị xóa.
Thông số
Tên | Loại | Mô tả |
---|---|---|
text | String | nội dung văn bản mới |
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setTextAlignment(textAlignment)
Đặt căn chỉnh văn bản. Các kiểu căn chỉnh có sẵn là DocumentApp.TextAlignment.NORMAL
, DocumentApp.TextAlignment.SUBSCRIPT
và DocumentApp.TextAlignment.SUPERSCRIPT
.
// Make the entire first paragraph be superscript. var text = DocumentApp.getActiveDocument().getBody().getParagraphs()[0].editAsText(); text.setTextAlignment(DocumentApp.TextAlignment.SUPERSCRIPT);
Thông số
Tên | Loại | Mô tả |
---|---|---|
textAlignment | TextAlignment | loại căn chỉnh văn bản sẽ áp dụng |
Hai chiều
Paragraph
— phần tử hiện tại
Ủy quyền
Tập lệnh sử dụng phương thức này yêu cầu ủy quyền với một hoặc nhiều phạm vi sau:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents