Class Paragraph

Đoạn văn

Phần tử đại diện cho một đoạn. Paragraph có thể chứa 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 các ký tự dòng mới. Các ký tự dòng mới ("\n") là được chuyển đổi thành ký tự ngắt dòng ("\r").

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

// Append a tab 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ứcLoại dữ liệu trả vềMô tả ngắn
addPositionedImage(image)PositionedImageTạo và chèn một PositionedImage mới qua blob hình ảnh được chỉ định.
appendHorizontalRule()HorizontalRuleTạo và thêm HorizontalRule mới.
appendInlineImage(image)InlineImageTạo và nối một InlineImage mới từ blob hình ảnh được chỉ định.
appendInlineImage(image)InlineImageThêm InlineImage đã cho.
appendPageBreak()PageBreakTạo và thêm PageBreak mới.
appendPageBreak(pageBreak)PageBreakThêm PageBreak đã cho.
appendText(text)TextTạo và thêm phần tử Text mới có nội dung được chỉ định.
appendText(text)TextThêm phần tử Text đã cho.
clear()ParagraphXoá nội dung của phần tử.
copy()ParagraphTrả về một bản sao sâu, tách biệt của phần tử hiện tại.
editAsText()TextLấy phiên bản Text của phần tử hiện tại để chỉnh sửa.
findElement(elementType)RangeElementTìm kiếm nội dung của phần tử cho thành phần con của loại đã chỉ định.
findElement(elementType, from)RangeElementTìm kiếm nội dung của phần tử cho thành phần con của loại đã chỉ định, bắt đầu từ RangeElement được chỉ định.
findText(searchPattern)RangeElementTìm kiếm nội dung của phần tử cho mẫu văn bản được chỉ định bằng cách sử dụng biểu thức chính quy.
findText(searchPattern, from)RangeElementTìm kiếm nội dung của phần tử cho mẫu văn bản được chỉ định, bắt đầu từ một mẫu văn bản cho trước kết quả tìm kiếm.
getAlignment()HorizontalAlignmentTruy xuất HorizontalAlignment.
getAttributes()ObjectTruy xuất các thuộc tính của phần tử.
getChild(childIndex)ElementTruy xuất phần tử con tại chỉ mục con đã chỉ định.
getChildIndex(child)IntegerTruy xuất chỉ mục con cho phần tử con đã chỉ định.
getHeading()ParagraphHeadingTruy xuất ParagraphHeading.
getIndentEnd()NumberTruy xuất thụt lề cuối, tính bằng điểm.
getIndentFirstLine()NumberTruy xuất thụt lề dòng đầu tiên, tính bằng điểm.
getIndentStart()NumberTruy xuất thụt lề bắt đầu.
getLineSpacing()NumberTruy xuất khoảng cách dòng, tính bằng điểm.
getLinkUrl()StringTruy xuất URL của đường liên kết.
getNextSibling()ElementTruy xuất phần tử đồng cấp tiếp theo của phần tử đó.
getNumChildren()IntegerTruy xuất số phần tử con.
getParent()ContainerElementTruy xuất phần tử mẹ của phần tử đó.
getPositionedImage(id)PositionedImageNhận PositionedImage theo mã nhận dạng của hình ảnh.
getPositionedImages()PositionedImage[]Lấy tất cả đối tượng PositionedImage được liên kết với đoạn.
getPreviousSibling()ElementTruy xuất phần tử đồng cấp trước đó của phần tử.
getSpacingAfter()NumberTruy xuất khoảng cách sau phần tử, tính bằng điểm.
getSpacingBefore()NumberTruy xuất khoảng cách trước phần tử, tính bằng điểm.
getText()StringTruy xuất nội dung của phần tử dưới dạng chuỗi văn bản.
getTextAlignment()TextAlignmentXem cách căn chỉnh văn bản.
getType()ElementTypeTruy xuất ElementType của phần tử.
insertHorizontalRule(childIndex)HorizontalRuleTạo và chèn HorizontalRule tại chỉ mục đã chỉ định.
insertInlineImage(childIndex, image)InlineImageTạo và chèn một InlineImage mới từ blob hình ảnh đã chỉ định, tại vị trí được chỉ định chỉ mục.
insertInlineImage(childIndex, image)InlineImageChèn InlineImage đã cho vào chỉ mục được chỉ định.
insertPageBreak(childIndex)PageBreakTạo và chèn một PageBreak mới tại chỉ mục đã chỉ định.
insertPageBreak(childIndex, pageBreak)PageBreakChèn PageBreak đã cho vào chỉ mục được chỉ định.
insertText(childIndex, text)TextTạo và chèn một phần tử văn bản mới tại chỉ mục đã chỉ định.
insertText(childIndex, text)TextChèn phần tử Text đã cho vào chỉ mục đã chỉ định kèm theo văn bản đã chỉ định .
isAtDocumentEnd()BooleanXác định xem phần tử có nằm ở cuối Document hay không.
isLeftToRight()BooleanTruy xuất chế độ cài đặt từ trái sang phải.
merge()ParagraphHợp nhất phần tử với phần tử đồng cấp trước đó thuộc cùng loại.
removeChild(child)ParagraphXoá phần tử con đã chỉ định.
removeFromParent()ParagraphXoá phần tử khỏi phần tử mẹ.
removePositionedImage(id)BooleanXoá PositionedImage theo mã nhận dạng của hình ảnh.
replaceText(searchPattern, replacement)ElementThay thế tất cả các lần xuất hiện của một mẫu văn bản cho trước bằng một chuỗi thay thế cho trước, sử dụng thông thường biểu thức.
setAlignment(alignment)ParagraphThiết lập HorizontalAlignment.
setAttributes(attributes)ParagraphThiết lập các thuộc tính của phần tử.
setHeading(heading)ParagraphThiết lập ParagraphHeading.
setIndentEnd(indentEnd)ParagraphĐặt thụt lề cuối, tính bằng điểm.
setIndentFirstLine(indentFirstLine)ParagraphĐặt thụt lề dòng đầu tiên, tính bằng điểm.
setIndentStart(indentStart)ParagraphĐặt mức thụt lề đầu, tính bằng điểm.
setLeftToRight(leftToRight)ParagraphĐặt chế độ cài đặt từ trái sang phải.
setLineSpacing(multiplier)ParagraphĐặt giãn cách dòng, dưới dạng đại lượng cho biết số lượng dòng cần sử dụng để giãn cách.
setLinkUrl(url)ParagraphĐặt URL của đường 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ử, tính bằng điểm.
setText(text)voidĐặt nội dung của đoạ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 qua blob hình ảnh đượ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(DOCUMENT_ID);

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().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 tab, anchored to the first paragraph.
paragraph.addPositionedImage(image);

Tham số

TênLoạiMô tả
imageBlobSourceDữ liệu hình ảnh.

Cầu thủ trả bóng

PositionedImage — Hình ảnh mới được đị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

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

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Gets the first paragraph from the body.
const paragraph = body.getParagraphs()[0];

// Adds a horizontal line under the first paragraph.
paragraph.appendHorizontalRule();

Cầu thủ trả bóng

HorizontalRule — Quy tắc mới theo chiều ngang.

Ủ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à nối một InlineImage mới từ blob hình ảnh đượ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(DOCUMENT_ID);

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().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);

Tham số

TênLoạiMô tả
imageBlobSourceDữ liệu hình ảnh.

Cầu thủ trả bóng

InlineImage — Hình ảnh đượ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

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

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().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);

Tham số

TênLoạiMô tả
imageInlineImageDữ liệu hình ảnh.

Cầu thủ trả bóng

InlineImage — Hình ảnh đượ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

appendPageBreak()

Tạo và thêm PageBreak mới.

Lưu ý: PageBreaks có thể không có trong TableCells. Nếu phần tử hiện tại có trong một ô của bảng, thì hệ thống 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(DOCUMENT_ID);

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Gets the first paragraph from the body.
const paragraph = body.getParagraphs()[0];

// Adds a page break after the first paragraph.
paragraph.appendPageBreak();

Cầu thủ trả bóng

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 được chứa PageBreaks trong TableCells. Nếu phần tử hiện tại tồn tại trong một ô của 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(DOCUMENT_ID);

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().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);

Tham số

TênLoạiMô tả
pageBreakPageBreakNgắt trang cần thêm.

Cầu thủ trả bóng

PageBreak — Phần tử ngắt trang đã 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 có 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(DOCUMENT_ID);

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().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.');

Tham số

TênLoạiMô tả
textStringNội dung văn bản.

Cầu thủ trả bóng

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

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

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().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);

Tham số

TênLoạiMô tả
textTextPhần tử văn bản cần thêm.

Cầu thủ trả bóng

Text — Phần tử văn bản đã 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

clear()

Xoá nội dung của phần tử.

Cầu thủ trả bóng

Paragraph — Phần tử hiện tại.


copy()

Trả về một bản sao sâu, tách biệt của phần tử hiện tại.

Mọi phần tử con có trong phần tử đó cũng được sao chép. Phần tử mới không có cha mẹ.

Cầu thủ trả bóng

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 để chỉnh sửa nội dung các phần tử ở dạng văn bản đa dạng thức. Chế độ editAsText bỏ qua các phần tử không phải văn bản (chẳng hạn như InlineImageHorizontalRule).

Các phần tử con nằm hoàn toàn trong một dải ô văn bản đã bị xoá sẽ bị xoá khỏi phần tử đó.

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

Cầu thủ trả bóng

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 của loại đã chỉ định.

Tham số

TênLoạiMô tả
elementTypeElementTypeLoại phần tử cần tìm kiếm.

Cầu thủ trả bóng

RangeElement – Một 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 của loại đã chỉ định, bắt đầu từ RangeElement được chỉ định.

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

Tham số

TênLoạiMô tả
elementTypeElementTypeLoại phần tử cần tìm kiếm.
fromRangeElementKết quả tìm kiếm để tìm kiếm.

Cầu thủ trả bóng

RangeElement – Một 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 được chỉ định bằng cách sử dụng biểu thức chính quy.

Một số tính năng trong biểu thức chính quy JavaScript không được hỗ trợ đầy đủ, chẳng hạn như nhóm thu thập và đối tượng sửa đổi chế độ.

Mẫu biểu thức chính quy đã 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.

Tham số

TênLoạiMô tả
searchPatternStringmẫu tìm kiếm

Cầu thủ trả bóng

RangeElement – một 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ó văn bản 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 được chỉ định, bắt đầu từ một mẫu văn bản cho trước kết quả tìm kiếm.

Một số tính năng trong biểu thức chính quy JavaScript không được hỗ trợ đầy đủ, chẳng hạn như nhóm thu thập và đối tượng sửa đổi chế độ.

Mẫu biểu thức chính quy đã 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.

Tham số

TênLoạiMô tả
searchPatternStringmẫu tìm kiếm
fromRangeElementkết quả tìm kiếm để tìm kiếm

Cầu thủ trả bóng

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ó 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(DOCUMENT_ID);

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().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());

Cầu thủ trả bóng

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 từng thuộc tính phần tử hợp lệ, trong đó mỗi thuộc tính tên thuộc tính tương ứng với một mục trong bản liệt kê DocumentApp.Attribute.

var doc = DocumentApp.getActiveDocument();
var documentTab = doc.getActiveTab().asDocumentTab();
var body = documentTab.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]);
}

Cầu thủ trả bóng

Object – Các 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.

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

// Obtain the first element in the tab.
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.");
}

Tham số

TênLoạiMô tả
childIndexIntegerChỉ mục của phần tử con cần truy xuất.

Cầu thủ trả bóng

Element – Phần tử con trong chỉ mụ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 được chỉ định.

Tham số

TênLoạiMô tả
childElementPhần tử con để truy xuất chỉ mục.

Cầu thủ trả bóng

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

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().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());

Cầu thủ trả bóng

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 xuất thụt lề cuối, tính bằng điểm.

Cầu thủ trả bóng

Number — thụt lề kết thúc, 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

getIndentFirstLine()

Truy xuất thụt lề dòng đầu tiên, tính bằng điểm.

Cầu thủ trả bóng

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ề bắt đầu.

Cầu thủ trả bóng

Number — thụt lề bắt đầ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

getLineSpacing()

Truy xuất khoảng cách dòng, tính bằng điểm.

Cầu thủ trả bóng

Number — giãn 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 của đường liên kết.

Cầu thủ trả bóng

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ử đồng cấp tiếp theo của phần tử đó.

Phần tử đồng cấp tiếp theo có cùng phần tử mẹ và theo sau phần tử hiện tại.

Cầu thủ trả bóng

Element – Phần tử đồng cấp 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ố phần tử con.

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

// Log the number of elements in the tab.
Logger.log("There are " + body.getNumChildren() +
    " elements in the tab's body.");

Cầu thủ trả bóng

Integer — Số lượng trẻ em.

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

Cầu thủ trả bóng

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.

Tham số

TênLoạiMô tả
idStringmã hình ảnh

Cầu thủ trả bóng

PositionedImage – hình ảnh đã được đị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 được liên kết với đoạn.

Cầu thủ trả bóng

PositionedImage[] – một danh sách các hình ảnh đã được đị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ử.

Phần tử đồng cấp trước có cùng phần tử mẹ và đứng trước phần tử hiện tại.

Cầu thủ trả bóng

Element – Phần tử đồng cấp 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.

Cầu thủ trả bóng

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.

Cầu thủ trả bóng

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.

Cầu thủ trả bóng

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 hiện có thể dùng là DocumentApp.TextAlignment.NORMAL, DocumentApp.TextAlignment.SUBSCRIPTDocumentApp.TextAlignment.SUPERSCRIPT.

Cầu thủ trả bóng

TextAlignment – loại căn chỉnh văn bản hoặc null nếu văn bản chứa nhiều loại văn bản hoặc nếu căn chỉnh văn bản chưa bao giờ đượ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ử.

Dùng getType() để xác định loại chính xác của một phần tử nhất định.

var doc = DocumentApp.getActiveDocument();
var documentTab = doc.getActiveTab().asDocumentTab();
var body = documentTab.getBody();

// Obtain the first element in the active tab's 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.');
}

Cầu thủ trả bóng

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 HorizontalRule tại chỉ mục đã chỉ định.

Tham số

TênLoạiMô tả
childIndexIntegerchỉ mục mà bạn muốn chèn phần tử

Cầu thủ trả bóng

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 vị trí được chỉ định chỉ mục.

Tham số

TênLoạiMô tả
childIndexIntegerchỉ mục mà bạn muốn chèn phần tử
imageBlobSourcedữ liệu hình ảnh

Cầu thủ trả bóng

InlineImage – phần tử hình ảnh cùng dòng đã 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 vào chỉ mục được chỉ định.

Tham số

TênLoạiMô tả
childIndexIntegerchỉ mục mà bạn muốn chèn phần tử
imageInlineImagedữ liệu hình ảnh

Cầu thủ trả bóng

InlineImage – phần tử hình ảnh cùng dòng đã 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 tại chỉ mục đã chỉ định.

Lưu ý: PageBreaks có thể không có trong TableCells. Nếu phần tử hiện tại có trong một ô của bảng, thì hệ thống sẽ gửi một ngoại lệ.

Tham số

TênLoạiMô tả
childIndexIntegerchỉ mục mà bạn muốn chèn phần tử

Cầu thủ trả bóng

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 vào chỉ mục được chỉ định.

Lưu ý: PageBreaks có thể không có trong TableCells. Nếu phần tử hiện tại có trong một ô của bảng, thì hệ thống sẽ gửi một ngoại lệ.

Tham số

TênLoạiMô tả
childIndexIntegerchỉ mục mà bạn muốn chèn phần tử
pageBreakPageBreakkhoảng nghỉ

Cầu thủ trả bóng

PageBreak — phần tử ngắt trang đã 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 đã chỉ định.

Tham số

TênLoạiMô tả
childIndexIntegerchỉ mục mà bạn muốn chèn phần tử
textStringnội dung văn bản

Cầu thủ trả bóng

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 kèm theo văn bản đã chỉ định .

Tham số

TênLoạiMô tả
childIndexIntegerchỉ mục mà bạn muốn chèn phần tử
textTextthành phần văn bản cần chèn

Cầu thủ trả bóng

Text — thành phần văn bản đã 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ó nằm ở cuối Document hay không.

Cầu thủ trả bóng

Boolean – Liệu phần tử này có nằm ở cuối thẻ 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 chế độ cài đặt từ trái sang phải.

Cầu thủ trả bóng

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ử với phần tử đồng cấp trước đó thuộc cùng loại.

Chỉ có thể hợp nhất các phần tử của cùng một ElementType. Mọi phần tử con có trong phần tử hiện tại sẽ được di chuyển đến phần tử cùng cấp trước đó.

Phần tử hiện tại sẽ bị xoá khỏi tài liệu.

var doc = DocumentApp.getActiveDocument();
var documentTab = doc.getActiveTab().asDocumentTab();
var body = documentTab.getBody();

// Example 1: Merge paragraphs
// Append two paragraphs to the document's active tab.
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();

Cầu thủ trả bóng

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.

Tham số

TênLoạiMô tả
childElementphần tử con cần xoá

Cầu thủ trả bóng

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

Xoá phần tử khỏi phần tử mẹ.

var doc = DocumentApp.getActiveDocument();
var documentTab = doc.getActiveTab().asDocumentTab()
var body = documentTab.getBody();

// Remove all images in the active tab's body.
var imgs = body.getImages();
for (var i = 0; i < imgs.length; i++) {
  imgs[i].removeFromParent();
}

Cầu thủ trả bóng

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.

Tham số

TênLoạiMô tả
idStringmã hình ảnh

Cầu thủ trả bóng

Boolean – hình ảnh được chỉ định đã bị xoá hay chưa

Ủ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 cho trước bằng một chuỗi thay thế cho trước, sử dụng thông thường biểu thức.

Mẫu tìm kiếm được chuyển dưới dạng chuỗi, không phải là đối tượng biểu thức chính quy JavaScript. Do đó, bạn cần thoát khỏi mọi dấu gạch chéo ngược trong mẫu.

Phương thức này sử dụng mã thông thường RE2 của Google thư viện biểu thức để giới hạn cú pháp được hỗ trợ.

Mẫu biểu thức chính quy đã 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().getActiveTab().asDocumentTab().getBody();

// Clear the text surrounding "Apps Script", with or without text.
body.replaceText("^.*Apps ?Script.*$", "Apps Script");

Tham số

TênLoạiMô tả
searchPatternStringmẫu biểu thức chính quy để tìm kiếm
replacementStringvăn bản để sử dụng để thay thế

Cầu thủ trả bóng

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)

Thiết lập HorizontalAlignment.

Tham số

TênLoạiMô tả
alignmentHorizontalAlignmentcăn chỉnh ngang

Cầu thủ trả bóng

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)

Thiết lập các thuộc tính của phần tử.

Thông 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ản liệt kê DocumentApp.Attribute và mỗi giá trị thuộc tính là một giá trị mới áp dụng.

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

Tham số

TênLoạiMô tả
attributesObjectCác thuộc tính của phần tử.

Cầu thủ trả bóng

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)

Thiết lập ParagraphHeading.

Tham số

TênLoạiMô tả
headingParagraphHeadingtiêu đề

Cầu thủ trả bóng

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 mức thụt lề cuối, tính bằng điểm.

Tham số

TênLoạiMô tả
indentEndNumberthụt lề cuối đoạn, tính bằng điểm

Cầu thủ trả bóng

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, tính bằng điểm.

Tham số

TênLoạiMô tả
indentFirstLineNumberthụt lề dòng đầu tiên, tính bằng điểm

Cầu thủ trả bóng

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 mức thụt lề đầu, tính bằng điểm.

Tham số

TênLoạiMô tả
indentStartNumberthụt lề bắt đầu, tính bằng điểm

Cầu thủ trả bóng

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 chế độ cài đặt từ trái sang phải.

Tham số

TênLoạiMô tả
leftToRightBooleanchế độ cài đặt từ trái sang phải

Cầu thủ trả bóng

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 giãn cách dòng, dưới dạng đại lượng cho biết số lượng dòng cần sử dụng để giãn cách.

Tham số

TênLoạiMô tả
multiplierNumbersố dòng

Cầu thủ trả bóng

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)

Đặt URL của đường liên kết.

Tham số

TênLoạiMô tả
urlStringURL của đường liên kết

Cầu thủ trả bóng

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

setSpacingAfter(spacingAfter)

Đặt khoảng cách sau phần tử, tính bằng điểm.

Tham số

TênLoạiMô tả
spacingAfterNumberkhoảng cách sau phần tử, tính theo điểm

Cầu thủ trả bóng

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ử, tính bằng điểm.

Tham số

TênLoạiMô tả
spacingBeforeNumberkhoảng cách trước phần tử, tính bằng điểm

Cầu thủ trả bóng

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 dưới dạng văn bản.

Lưu ý: các nội dung hiện có sẽ bị xoá.

Tham số

TênLoạiMô tả
textStringnộ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ó thể dùng là DocumentApp.TextAlignment.NORMAL, DocumentApp.TextAlignment.SUBSCRIPTDocumentApp.TextAlignment.SUPERSCRIPT.

// Make the entire first paragraph in the active tab be superscript.
var documentTab = DocumentApp.getActiveDocument().getActiveTab().asDocumentTab();
var text = documentTab.getBody().getParagraphs()[0].editAsText();
text.setTextAlignment(DocumentApp.TextAlignment.SUPERSCRIPT);

Tham số

TênLoạiMô tả
textAlignmentTextAlignmentloại căn chỉnh văn bản sẽ áp dụng

Cầu thủ trả bóng

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