代表內嵌圖片的元素。Inline
可包含在 List
或 Paragraph
中,但 List
或 Paragraph
位於 Footnote
內時除外。Inline
本身不得包含任何其他元素。如要進一步瞭解文件結構,請參閱擴充 Google 文件指南。
方法
方法 | 傳回類型 | 簡短說明 |
---|---|---|
copy() | Inline | 傳回目前元素的深層副本,且該副本已分離。 |
get | String | 傳回圖片的替代說明。 |
get | String | 傳回圖片的替代標題。 |
get | Blob | 以轉換為指定內容類型的 Blob 形式,傳回這個物件內的資料。 |
get | Object | 擷取元素的屬性。 |
get | Blob | 將這個物件內的資料以 Blob 形式傳回。 |
get | Integer | 擷取圖片的高度 (以像素為單位)。 |
get | String | 擷取連結網址。 |
get | Element | 擷取元素的下一個同層級元素。 |
get | Container | 擷取元素的父項元素。 |
get | Element | 擷取元素的前一個同層級元素。 |
get | Element | 擷取元素的 Element 。 |
get | Integer | 以像素為單位擷取圖片寬度。 |
is | Boolean | 判斷元素是否位於 Document 的結尾。 |
merge() | Inline | 將元素與相同類型的前一個同層級元素合併。 |
remove | Inline | 從父項移除元素。 |
set | Inline | 設定圖片的替代說明。 |
set | Inline | 設定圖片的替代標題。 |
set | Inline | 設定元素的屬性。 |
set | Inline | 設定圖片的高度,以像素為單位。 |
set | Inline | 設定連結網址。 |
set | Inline | 設定圖片寬度,以像素為單位。 |
內容詳盡的說明文件
copy()
傳回目前元素的深層副本,且該副本已分離。
元素中的任何子項元素也會一併複製。新元素沒有父項。
回攻員
Inline
:新副本。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
get Alt Description()
傳回圖片的替代說明。
回攻員
String
:替代說明,或 null
(如果元素沒有替代說明)。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
get Alt Title()
傳回圖片的替代標題。
回攻員
String
:替代標題,如果元素沒有替代標題,則為 null
。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
get As(contentType)
以轉換為指定內容類型的 Blob 形式,傳回這個物件內的資料。這個方法會在檔案名稱中加入適當的副檔名,例如「myfile.pdf」。不過,系統會假設檔案名稱中最後一個半形句點 (如有) 後方的部分是現有副檔名,應予以取代。因此,「ShoppingList.12.25.2014」會變成「ShoppingList.12.25.pdf」。
如要查看每日轉換配額,請參閱「Google 服務配額」。新建立的 Google Workspace 網域可能暫時會受到較嚴格的配額限制。
參數
名稱 | 類型 | 說明 |
---|---|---|
content | String | 要轉換成的 MIME 類型。對於大多數的 Blob,'application/pdf' 是唯一有效的選項。如果是 BMP、GIF、JPEG 或 PNG 格式的圖片,'image/bmp' 、'image/gif' 、'image/jpeg' 或 'image/png' 也有效。如果是 Google 文件,'text/markdown' 也適用。 |
回攻員
Blob
:以 Blob 形式呈現的資料。
get Attributes()
擷取元素的屬性。
結果會是物件,其中包含每個有效元素屬性的屬性,且每個屬性名稱都對應至 Document
列舉中的項目。
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]}`); }
回攻員
Object
:元素的屬性。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
get Blob()
get Height()
擷取圖片的高度 (以像素為單位)。
回攻員
Integer
:圖片的高度,以像素為單位
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
get Link Url()
擷取連結網址。
回攻員
String
:連結網址,或 null
(如果元素包含這項屬性的多個值)。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
get Next Sibling()
get Parent()
擷取元素的父項元素。
父項元素包含目前的元素。
回攻員
Container
:父項元素。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
get Previous Sibling()
get Type()
擷取元素的 Element
。
使用 get
判斷指定元素的確切類型。
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.'); }
回攻員
Element
:元素類型。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
get Width()
以像素為單位擷取圖片寬度。
回攻員
Integer
:圖片的寬度,以像素為單位
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
is At Document End()
merge()
將元素與相同類型的前一個同層級元素合併。
只能合併相同 Element
的元素。目前元素中包含的所有子項元素都會移至前一個同層級元素。
目前元素會從文件中移除。
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();
回攻員
Inline
:合併的元素。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
remove From Parent()
從父項移除元素。
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(); }
回攻員
Inline
:已移除的元素。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
set Alt Description(description)
設定圖片的替代說明。如果指定標題為 null
,則會將說明設為空字串。
參數
名稱 | 類型 | 說明 |
---|---|---|
description | String | 替代說明。 |
回攻員
Inline
:目前的物件。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
set Alt Title(title)
設定圖片的替代標題。如果指定標題為 null
,則將標題設為空字串。
參數
名稱 | 類型 | 說明 |
---|---|---|
title | String | 替代標題。 |
回攻員
Inline
:目前的物件。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
set Attributes(attributes)
設定元素的屬性。
指定的屬性參數必須是物件,其中每個屬性名稱都是 Document
列舉中的項目,每個屬性值都是要套用的新值。
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);
參數
名稱 | 類型 | 說明 |
---|---|---|
attributes | Object | 元素的屬性。 |
回攻員
Inline
:目前的元素。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
set Height(height)
設定圖片的高度,以像素為單位。
參數
名稱 | 類型 | 說明 |
---|---|---|
height | Integer | 圖片的高度 (以像素為單位) |
回攻員
Inline
- 目前物件
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
set Link Url(url)
設定連結網址。如果指定網址為 null
或空字串,這個方法會建立網址為空白的連結,這類連結在 Google 文件中可能會顯示為「無效連結」。
參數
名稱 | 類型 | 說明 |
---|---|---|
url | String | 連結網址。 |
回攻員
Inline
:目前的物件。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
set Width(width)
設定圖片寬度,以像素為單位。
參數
名稱 | 類型 | 說明 |
---|---|---|
width | Integer | 圖片的寬度 (以像素為單位) |
回攻員
Inline
- 目前物件
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents