Class InlineDrawing

Bản vẽnội tuyến

Một phần tử đại diện cho bản vẽ được nhúng. InlineDrawing có thể nằm trong ListItem hoặc Paragraph, trừ phi ListItem hoặc Paragraph nằm trong FootnoteSection. Bản thân InlineDrawing không thể chứa bất kỳ phần tử nào khác. Để biết thêm thông tin về cấu trúc tài liệu, hãy xem hướng dẫn về cách mở rộng Google Tài liệu.

Phương thức

Phương thứcKiểu dữ liệu trả vềMô tả ngắn
copy()InlineDrawingTrả về một bản sao tách biệt, sao chép sâu của phần tử hiện tại.
getAltDescription()StringTrả về nội dung mô tả thay thế của bản vẽ.
getAltTitle()StringTrả về tiêu đề thay thế của bản vẽ.
getAttributes()ObjectTruy xuất các thuộc tính của phần tử.
getNextSibling()ElementTruy xuất phần tử anh chị em tiếp theo của phần tử.
getParent()ContainerElementTruy xuất phần tử mẹ của phần tử.
getPreviousSibling()ElementTruy xuất phần tử anh chị em trước đó của phần tử.
getType()ElementTypeTruy xuất ElementType của phần tử.
isAtDocumentEnd()BooleanXác định xem phần tử có ở cuối Document hay không.
merge()InlineDrawingHợp nhất phần tử này với phần tử cùng loại đứng trước.
removeFromParent()InlineDrawingXoá phần tử khỏi phần tử mẹ.
setAltDescription(description)InlineDrawingĐặt nội dung mô tả thay thế cho bản vẽ.
setAltTitle(title)InlineDrawingĐặt tiêu đề thay thế cho bản vẽ.
setAttributes(attributes)InlineDrawingĐặt các thuộc tính của phần tử.

Tài liệu chi tiết

copy()

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

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

Cầu thủ trả bóng

InlineDrawing – Bản sao mới.

Ủy quyền

Các tập lệnh sử dụng phương thức này cần được uỷ quyền bằng một hoặc nhiều phạm vi sau đây:

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

getAltDescription()

Trả về nội dung mô tả thay thế của bản vẽ.

Cầu thủ trả bóng

String – Nội dung mô tả thay thế hoặc null nếu phần tử không có nội dung mô tả thay thế.

Ủy quyền

Các tập lệnh sử dụng phương thức này cần được uỷ quyền bằng một hoặc nhiều phạm vi sau đây:

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

getAltTitle()

Trả về tiêu đề thay thế của bản vẽ.

Cầu thủ trả bóng

String – Tiêu đề thay thế hoặc null nếu phần tử không có tiêu đề thay thế.

Ủy quyền

Các tập lệnh sử dụng phương thức này cần được uỷ quyền bằng một hoặc nhiều phạm vi sau đây:

  • 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 phép liệt kê DocumentApp.Attribute.

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

// Append a styled paragraph.
const par = body.appendParagraph('A bold, italicized paragraph.');
par.setBold(true);
par.setItalic(true);

// Retrieve the paragraph's attributes.
const atts = par.getAttributes();

// Log the paragraph attributes.
for (const att in atts) {
  Logger.log(`${att}:${atts[att]}`);
}

Cầu thủ trả bóng

Object – Thuộc tính của phần tử.

Ủy quyền

Các tập lệnh sử dụng phương thức này cần được uỷ quyền bằng một hoặc nhiều phạm vi sau đây:

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

getNextSibling()

Truy xuất phần tử anh chị em tiếp theo của phần tử.

Phần tử anh chị em tiếp theo có cùng phần tử mẹ và nằm sau phần tử hiện tại.

Cầu thủ trả bóng

Element — Phần tử anh chị em tiếp theo.

Ủy quyền

Các tập lệnh sử dụng phương thức này cần được uỷ quyền bằng một hoặc nhiều phạm vi sau đây:

  • 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

Các tập lệnh sử dụng phương thức này cần được uỷ quyền bằng một hoặc nhiều phạm vi sau đây:

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

getPreviousSibling()

Truy xuất phần tử anh chị em trước đó của phần tử.

Phần tử anh chị em 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ử anh chị em trước đó.

Ủy quyền

Các tập lệnh sử dụng phương thức này cần được uỷ quyền bằng một hoặc nhiều phạm vi sau đây:

  • 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 chính xác loại của một phần tử nhất định.

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

// Obtain the first element in the active tab's body.

const 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

Các tập lệnh sử dụng phương thức này cần được uỷ quyền bằng một hoặc nhiều phạm vi sau đây:

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

Cầu thủ trả bóng

Boolean – Cho biết phần tử có nằm ở cuối thẻ hay không.

Ủy quyền

Các tập lệnh sử dụng phương thức này cần được uỷ quyền bằng một hoặc nhiều phạm vi sau đây:

  • 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 phần tử cùng loại đứng trước.

Bạn 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 sẽ được chuyển đến phần tử anh chị em liền kề.

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

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

// Example 1: Merge paragraphs
// Append two paragraphs to the document's active tab.
const par1 = body.appendParagraph('Paragraph 1.');
const 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.
const cells = [
  ['Row 1, Cell 1', 'Row 1, Cell 2'],
  ['Row 2, Cell 1', 'Row 2, Cell 2'],
];
// Build a table from the array.
const table = body.appendTable(cells);
// Get the first row in the table.
const row = table.getRow(0);
// Get the two cells in this row.
const cell1 = row.getCell(0);
const cell2 = row.getCell(1);
// Merge the current cell into its preceding sibling element.
const merged = cell2.merge();

Cầu thủ trả bóng

InlineDrawing – Phần tử được hợp nhất.

Ủy quyền

Các tập lệnh sử dụng phương thức này cần được uỷ quyền bằng một hoặc nhiều phạm vi sau đây:

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

removeFromParent()

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

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

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

Cầu thủ trả bóng

InlineDrawing – Phần tử đã bị xoá.

Ủy quyền

Các tập lệnh sử dụng phương thức này cần được uỷ quyền bằng một hoặc nhiều phạm vi sau đây:

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

setAltDescription(description)

Đặt nội dung mô tả thay thế cho bản vẽ. Nếu nội dung mô tả đã cho là null, hãy đặt nội dung mô tả thành chuỗi trống.

Thông số

TênLoạiMô tả
descriptionStringNội dung mô tả thay thế.

Cầu thủ trả bóng

InlineDrawing – Đối tượng hiện tại.

Ủy quyền

Các tập lệnh sử dụng phương thức này cần được uỷ quyền bằng một hoặc nhiều phạm vi sau đây:

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

setAltTitle(title)

Đặt tiêu đề thay thế cho bản vẽ. Nếu tiêu đề đã cho là null, hãy đặt tiêu đề thành chuỗi trống.

Thông số

TênLoạiMô tả
titleStringTiêu đề thay thế.

Cầu thủ trả bóng

InlineDrawing – Đối tượng hiện tại.

Ủy quyền

Các tập lệnh sử dụng phương thức này cần được uỷ quyền bằng một hoặc nhiều phạm vi sau đây:

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

setAttributes(attributes)

Đặt 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 phép liệt kê DocumentApp.Attribute và mỗi giá trị thuộc tính là giá trị mới sẽ được áp dụng.

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

// Define a custom paragraph style.
const 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.
const par = body.appendParagraph('A paragraph with custom style.');

// Apply the custom style.
par.setAttributes(style);

Thông số

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

Cầu thủ trả bóng

InlineDrawing – Phần tử hiện tại.

Ủy quyền

Các tập lệnh sử dụng phương thức này cần được uỷ quyền bằng một hoặc nhiều phạm vi sau đây:

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