代表嵌入繪圖的元素。InlineDrawing
可以包含在 ListItem
或 Paragraph
中,除非 ListItem
或 Paragraph
位於 FootnoteSection
中。InlineDrawing
本身不得含有任何其他元素。如要進一步瞭解文件結構,請參閱擴充 Google 文件指南。
方法
方法 | 傳回類型 | 簡短說明 |
---|---|---|
copy() | InlineDrawing | 傳回目前元素的卸離的深度副本。 |
getAltDescription() | String | 傳回繪圖的替代說明。 |
getAltTitle() | String | 傳回繪圖的替代標題。 |
getAttributes() | Object | 擷取元素的屬性。 |
getNextSibling() | Element | 擷取元素的下一個同層級元素。 |
getParent() | ContainerElement | 擷取元素的父項元素。 |
getPreviousSibling() | Element | 擷取元素先前的同層級元素。 |
getType() | ElementType | 擷取元素的 ElementType 。 |
isAtDocumentEnd() | Boolean | 判斷元素是否位於 Document 的結尾。 |
merge() | InlineDrawing | 將元素與下一個同類型的同層級合併。 |
removeFromParent() | InlineDrawing | 從父項元素中移除元素。 |
setAltDescription(description) | InlineDrawing | 設定繪圖的替代說明。 |
setAltTitle(title) | InlineDrawing | 設定繪圖的替代標題。 |
setAttributes(attributes) | InlineDrawing | 設定元素的屬性。 |
內容詳盡的說明文件
copy()
傳回目前元素的卸離的深層副本。
系統也會複製元素中顯示的所有子元素。新元素沒有父項。
回攻員
InlineDrawing
:新副本。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getAltDescription()
傳回繪圖的替代說明。
回攻員
String
:替代標題;如果元素沒有替代標題,則為 null
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getAltTitle()
傳回繪圖的替代標題。
回攻員
String
:替代標題;如果元素沒有替代標題,則為 null
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getAttributes()
擷取元素的屬性。
結果是一個物件,其中包含每個有效元素屬性的屬性,其中每個屬性名稱都會對應 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]); }
回攻員
Object
:元素的屬性。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getNextSibling()
getParent()
擷取元素的父項元素。
父項元素包含目前的元素。
回攻員
ContainerElement
:父項元素。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getPreviousSibling()
getType()
擷取元素的 ElementType
。
使用 getType()
來判斷特定元素的確切類型。
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.'); }
回攻員
ElementType
:元素類型。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
isAtDocumentEnd()
merge()
將元素與下一個同類型的同層級合併。
只能合併相同 ElementType
的元素。目前元素中包含的任何子項元素都會移至上述同層級元素。
目前元素會從文件中移除。
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();
回攻員
InlineDrawing
:合併的元素。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
removeFromParent()
從父項元素中移除元素。
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(); }
回攻員
InlineDrawing
- 已移除的元素。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setAltDescription(description)
設定繪圖的替代說明。如果指定的標題為 null
,請將說明設為空白字串。
參數
名稱 | 類型 | 說明 |
---|---|---|
description | String | 替代標題 |
回攻員
InlineDrawing
:目前的物件
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setAltTitle(title)
設定繪圖的替代標題。如果指定的標題為 null
,請將標題設為空白字串。
參數
名稱 | 類型 | 說明 |
---|---|---|
title | String | 替代標題 |
回攻員
InlineDrawing
:目前的物件
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setAttributes(attributes)
設定元素的屬性。
指定的屬性參數必須是一個物件,其中每個屬性名稱都是 DocumentApp.Attribute
列舉中的一個項目,每個屬性值都是要套用的新值。
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);
參數
名稱 | 類型 | 說明 |
---|---|---|
attributes | Object | 元素的屬性。 |
回攻員
InlineDrawing
- 目前的元素。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents