Một phần tử đại diện cho bảng. Table
chỉ có thể chứa các phần tử TableRow
. Để 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.
Khi tạo một Table
chứa một số lượng lớn các hàng hoặc ô, hãy cân nhắc tạo Table
từ một mảng chuỗi, như minh hoạ trong ví dụ sau.
var body = DocumentApp.getActiveDocument().getBody(); // Create a two-dimensional array containing the 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. body.appendTable(cells);
Phương thức
Phương thức | Kiểu dữ liệu trả về | Mô tả ngắn |
---|---|---|
appendTableRow() | TableRow | Tạo và thêm một TableRow mới. |
appendTableRow(tableRow) | TableRow | Thêm TableRow đã cho. |
clear() | Table | Xoá nội dung của phần tử. |
copy() | Table | Trả về một 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ử để xem thành phần con của kiểu đã chỉ định. |
findElement(elementType, from) | RangeElement | Tìm kiếm nội dung của phần tử cho thành phần con của kiểu đã 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 được 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 được chỉ định, bắt đầu từ một kết quả tìm kiếm đã cho. |
getAttributes() | Object | Truy xuất các thuộc tính của phần tử. |
getBorderColor() | String | Truy xuất màu đường viền. |
getBorderWidth() | Number | Truy xuất chiều rộng đường viền, tính bằng điểm. |
getCell(rowIndex, cellIndex) | TableCell | Truy xuất TableCell tại các chỉ mục hàng và ô đã chỉ định. |
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. |
getColumnWidth(columnIndex) | Number | Truy xuất chiều rộng của cột đã chỉ định trong bả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 phần tử con. |
getNumRows() | Integer | Truy xuất số lượng TableRows . |
getParent() | ContainerElement | Truy xuất phần tử mẹ của phần tử. |
getPreviousSibling() | Element | Truy xuất phần tử phụ trước đó của phần tử. |
getRow(rowIndex) | TableRow | Truy xuất TableRow tại chỉ mục hàng đã chỉ định. |
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 | Lấy căn chỉnh văn bản. |
getType() | ElementType | Truy xuất ElementType của phần tử. |
insertTableRow(childIndex) | TableRow | Tạo và chèn một TableRow mới tại chỉ mục đã chỉ định. |
insertTableRow(childIndex, tableRow) | TableRow | Chèn TableRow đã cho vào chỉ mục đã chỉ định. |
isAtDocumentEnd() | Boolean | Xác định xem phần tử này có nằm ở cuối Document hay không. |
removeChild(child) | Table | Xoá phần tử con đã chỉ định. |
removeFromParent() | Table | Xoá phần tử khỏi phần tử mẹ. |
removeRow(rowIndex) | TableRow | Xoá TableRow tại chỉ mục hàng đã chỉ đị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 nhất định bằng một chuỗi thay thế nhất định, sử dụng các biểu thức chính quy. |
setAttributes(attributes) | Table | Thiết lập các thuộc tính của phần tử. |
setBorderColor(color) | Table | Đặt màu đường viền. |
setBorderWidth(width) | Table | Đặt chiều rộng đường viền, tính theo điểm. |
setColumnWidth(columnIndex, width) | Table | Đặt chiều rộng của cột được chỉ định, tính bằng điểm. |
setLinkUrl(url) | Table | Đặt URL của đường liên kết. |
setTextAlignment(textAlignment) | Table | Đặt cách căn chỉnh văn bản. |
Tài liệu chi tiết
appendTableRow()
appendTableRow(tableRow)
Thêm TableRow
đã 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 table in the document and copies the second row. const table = body.getTables()[0]; const row = table.getChild(1).copy(); // Adds the copied row to the bottom of the table. const tableRow = table.appendTableRow(row);
Các tham số
Tên | Loại | Nội dung mô tả |
---|---|---|
tableRow | TableRow | Hàng cần thêm trong bảng. |
Cầu thủ trả bóng
TableRow
– Phần tử hàng trong bảng được thêm vào.
Ủy quyền
Tập lệnh sử dụng phương thức này cần được uỷ 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ề một 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ử cũng được sao chép. Phần tử mới không có phần tử mẹ.
Cầu thủ trả bóng
Table
– Bản sao mới.
Ủy quyền
Tập lệnh sử dụng phương thức này cần được uỷ 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 các 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ử không phải văn bản (chẳng hạn như InlineImage
và HorizontalRule
).
Các phần tử con nằm trong phạm vi văn bản đã xoá sẽ bị xoá 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);
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ử để xem thành phần con của kiểu đã chỉ định.
Các tham số
Tên | Loại | Nội dung mô tả |
---|---|---|
elementType | ElementType | loạ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 cần được uỷ 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 kiểu đã 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; } }
Các tham số
Tên | Loại | Nội dung 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 |
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 cần được uỷ 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 biểu thức chính quy.
Một số tính năng của biểu thức chính quy JavaScript chưa được hỗ trợ đầy đủ, chẳng hạn như nhóm thu thập dữ liệu và đối tượng sửa đổi chế độ.
Mẫu biểu thức chính quy đã cung cấp đượ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.
Các tham số
Tên | Loại | Nội dung mô tả |
---|---|---|
searchPattern | String | mẫu 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 văn bản tìm kiếm hoặc để trống nếu không có kết quả nào trùng khớp
Ủy quyền
Tập lệnh sử dụng phương thức này cần được uỷ 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 kết quả tìm kiếm đã cho.
Một số tính năng của biểu thức chính quy JavaScript chưa được hỗ trợ đầy đủ, chẳng hạn như nhóm thu thập dữ liệu và đối tượng sửa đổi chế độ.
Mẫu biểu thức chính quy đã cung cấp đượ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.
Các tham số
Tên | Loại | Nội dung 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 |
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 để trống nếu không có kết quả nào phù hợp
Ủy quyền
Tập lệnh sử dụng phương thức này cần được uỷ 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 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]); }
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 cần được uỷ 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
getBorderColor()
Truy xuất màu đường viền.
// 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 table. const table = body.getTables()[0]; // Sets the border color of the first table. table.setBorderColor('#00FF00'); // Logs the border color of the first table to the console. console.log(table.getBorderColor());
Cầu thủ trả bóng
String
– Màu đường viền, được định dạng bằng ký hiệu CSS (như '#ffffff'
).
Ủy quyền
Tập lệnh sử dụng phương thức này cần được uỷ 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
getBorderWidth()
Truy xuất chiều rộng đường viền, tính bằng điểm.
// 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 table. const table = body.getTables()[0]; // Sets the border width of the first table. table.setBorderWidth(20); // Logs the border width of the first table. console.log(table.getBorderWidth());
Cầu thủ trả bóng
Number
– Chiều rộng đường viền, tính bằng điểm.
Ủy quyền
Tập lệnh sử dụng phương thức này cần được uỷ 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
getCell(rowIndex, cellIndex)
Truy xuất TableCell
tại các chỉ mục hàng và ô đã 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 table. const table = body.getTables()[0]; // Gets the cell of the table's third row and second column. const cell = table.getCell(2, 1); // Logs the cell text to the console. console.log(cell.getText());
Các tham số
Tên | Loại | Nội dung mô tả |
---|---|---|
rowIndex | Integer | Chỉ mục của hàng có chứa ô cần truy xuất. |
cellIndex | Integer | Chỉ mục của ô cần truy xuất. |
Cầu thủ trả bóng
TableCell
– Ô trong bảng.
Ủy quyền
Tập lệnh sử dụng phương thức này cần được uỷ 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."); }
Các tham số
Tên | Loại | Nội dung mô tả |
---|---|---|
childIndex | Integer | chỉ mục của phần tử con cần truy xuất |
Cầu thủ trả bóng
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 cần được uỷ 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.
Các tham số
Tên | Loại | Nội dung mô tả |
---|---|---|
child | Element | phần tử con cần 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 cần được uỷ 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
getColumnWidth(columnIndex)
Truy xuất chiều rộng của cột đã chỉ định trong bảng, tính bằng điểm.
// 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 table. const table = body.getTables()[0]; // Sets the width of the second column to 100 points. const columnWidth = table.setColumnWidth(1, 100); // Gets the width of the second column and logs it to the console. console.log(columnWidth.getColumnWidth(1));
Các tham số
Tên | Loại | Nội dung mô tả |
---|---|---|
columnIndex | Integer | Chỉ mục cột. |
Cầu thủ trả bóng
Number
– Chiều rộng của cột, tính bằng điểm.
Ủy quyền
Tập lệnh sử dụng phương thức này cần được uỷ 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.
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 cần được uỷ 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 đồng cấp tiếp theo có cùng thành phần mẹ và theo sau phần tử hiện tại.
Cầu thủ trả bóng
Element
– Phần tử phụ tiếp theo.
Ủy quyền
Tập lệnh sử dụng phương thức này cần được uỷ 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 phần tử 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.");
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 cần được uỷ 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
getNumRows()
Truy xuất số lượng TableRows
.
// 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 table. const table = body.getTables()[0]; // Logs the number of rows of the first table to the console. console.log(table.getNumRows());
Cầu thủ trả bóng
Integer
– Số lượng hàng trong bảng.
Ủy quyền
Tập lệnh sử dụng phương thức này cần được uỷ 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 cần được uỷ 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ử phụ trước đó của phần tử.
Thành phần đồng cấp trước có cùng thành phần mẹ và đứng trước phần tử hiện tại.
Cầu thủ trả bóng
Element
– Phần tử phụ trước đó.
Ủy quyền
Tập lệnh sử dụng phương thức này cần được uỷ 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
getRow(rowIndex)
Truy xuất TableRow
tại chỉ mục hàng đã 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 table and logs the text of first row to the console. const table = body.getTables()[0]; console.log(table.getRow(0).getText());
Các tham số
Tên | Loại | Nội dung mô tả |
---|---|---|
rowIndex | Integer | Chỉ mục của hàng cần truy xuất. |
Cầu thủ trả bóng
TableRow
– Hàng trong bảng.
Ủy quyền
Tập lệnh sử dụng phương thức này cần được uỷ 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 cần được uỷ 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()
Lấy căn chỉnh văn bản. Có các loại căn chỉnh là DocumentApp.TextAlignment.NORMAL
, DocumentApp.TextAlignment.SUBSCRIPT
và DocumentApp.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 căn chỉnh văn bản hoặc nếu chưa từng đặt cách căn chỉnh văn bản
Ủy quyền
Tập lệnh sử dụng phương thức này cần được uỷ 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.'); }
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 cần được uỷ 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
insertTableRow(childIndex)
Tạo và chèn một TableRow
mới tại chỉ mục đã chỉ định.
Các tham số
Tên | Loại | Nội dung mô tả |
---|---|---|
childIndex | Integer | chỉ mục để chèn phần tử |
Cầu thủ trả bóng
TableRow
– phần tử hiện tại
Ủy quyền
Tập lệnh sử dụng phương thức này cần được uỷ 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
insertTableRow(childIndex, tableRow)
Chèn TableRow
đã cho vào chỉ mục đã chỉ định.
Các tham số
Tên | Loại | Nội dung mô tả |
---|---|---|
childIndex | Integer | chỉ mục để chèn phần tử |
tableRow | TableRow | hàng trong bảng cần chèn |
Cầu thủ trả bóng
TableRow
— phần tử hàng trong bảng được chèn
Ủy quyền
Tập lệnh sử dụng phương thức này cần được uỷ 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ử này có nằm ở cuối Document
hay không.
Cầu thủ trả bóng
Boolean
– Liệu phần tử có nằm ở 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 cần được uỷ 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.
// 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 table. const table = body.getTables()[0]; // Finds the first table row and removes it. const element = table.findElement(DocumentApp.ElementType.TABLE_ROW); table.removeChild(element.getElement());
Các tham số
Tên | Loại | Nội dung mô tả |
---|---|---|
child | Element | Phần tử con cần xoá. |
Cầu thủ trả bóng
Table
– Phần tử hiện tại.
Ủy quyền
Tập lệnh sử dụng phương thức này cần được uỷ 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 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(); }
Cầu thủ trả bóng
Table
– Phần tử đã bị xoá.
Ủy quyền
Tập lệnh sử dụng phương thức này cần được uỷ 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
removeRow(rowIndex)
Xoá TableRow
tại chỉ mục hàng đã 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 table and removes its second row. const table = body.getTables()[0]; table.removeRow(1);
Các tham số
Tên | Loại | Nội dung mô tả |
---|---|---|
rowIndex | Integer | Chỉ mục của hàng cần xoá. |
Cầu thủ trả bóng
TableRow
– Hàng đã xoá.
Ủy quyền
Tập lệnh sử dụng phương thức này cần được uỷ 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 nhất định 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.
Phương thức này sử dụng thư viện biểu thức chính quy RE2 của Google. Thư viện này giới hạn cú pháp được hỗ trợ.
Mẫu biểu thức chính quy đã cung cấp đượ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");
Các tham số
Tên | Loại | Nội dung mô tả |
---|---|---|
searchPattern | String | mẫu biểu thức chính quy để tìm kiếm |
replacement | String | văn bản để 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 cần được uỷ 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ử.
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à một giá trị mới sẽ được á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);
Các tham số
Tên | Loại | Nội dung mô tả |
---|---|---|
attributes | Object | Thuộc tính của phần tử. |
Cầu thủ trả bóng
Table
– Phần tử hiện tại.
Ủy quyền
Tập lệnh sử dụng phương thức này cần được uỷ 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
setBorderColor(color)
Đặt màu đường viền.
// 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 table. const table = body.getTables()[0]; // Sets the border color of the table to green. table.setBorderColor('#00FF00');
Các tham số
Tên | Loại | Nội dung mô tả |
---|---|---|
color | String | Màu đường viền, được định dạng bằng ký hiệu CSS (như '#ffffff' ). |
Cầu thủ trả bóng
Table
– Phần tử hiện tại.
Ủy quyền
Tập lệnh sử dụng phương thức này cần được uỷ 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
setBorderWidth(width)
Đặt chiều rộng đường viền, tính theo điểm.
Các tham số
Tên | Loại | Nội dung mô tả |
---|---|---|
width | Number | chiều rộng đường viền, tính theo điểm |
Cầu thủ trả bóng
Table
– phần tử hiện tại
Ủy quyền
Tập lệnh sử dụng phương thức này cần được uỷ 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
setColumnWidth(columnIndex, width)
Đặt chiều rộng của cột được chỉ định, tính bằng điểm.
Các tham số
Tên | Loại | Nội dung mô tả |
---|---|---|
columnIndex | Integer | chỉ mục cột |
width | Number | chiều rộng đường viền, tính theo điểm |
Cầu thủ trả bóng
Table
– phần tử hiện tại
Ủy quyền
Tập lệnh sử dụng phương thức này cần được uỷ 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.
Các tham số
Tên | Loại | Nội dung mô tả |
---|---|---|
url | String | url liên kết |
Cầu thủ trả bóng
Table
– phần tử hiện tại
Ủy quyền
Tập lệnh sử dụng phương thức này cần được uỷ 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ách căn chỉnh văn bản. Có các loại căn chỉnh 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);
Các tham số
Tên | Loại | Nội dung mô tả |
---|---|---|
textAlignment | TextAlignment | loại căn chỉnh văn bản cần áp dụng |
Cầu thủ trả bóng
Table
– phần tử hiện tại
Ủy quyền
Tập lệnh sử dụng phương thức này cần được uỷ 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