Class InlineImage

透過集合功能整理內容 你可以依據偏好儲存及分類內容。
InlineImage

代表嵌入圖片的元素。除非 ListItemParagraphFootnoteSection 中,否則 InlineImage 可包含在 ListItemParagraph 中。InlineImage 本身不可包含任何其他元素。如要進一步瞭解文件結構,請參閱擴充 Google 文件的指南

方法

方法傳回類型簡短說明
copy()InlineImage傳回目前元素的卸離深層連結。
getAltDescription()String傳回圖片的替代說明。
getAltTitle()String傳回圖片的替代標題。
getAs(contentType)Blob傳回此物件中的資料,以轉換為指定內容類型的 blob。
getAttributes()Object擷取元素的屬性。
getBlob()Blob傳回這個物件中的資料,以 blob 形式傳回。
getHeight()Integer擷取圖片的高度 (以像素為單位)。
getLinkUrl()String擷取連結網址。
getNextSibling()Element擷取元素和下一個下一個同層級元素。
getParent()ContainerElement擷取元素的父項元素。
getPreviousSibling()Element擷取元素的先前同層級元素。
getType()ElementType擷取元素的 ElementType
getWidth()Integer擷取圖片的寬度 (以像素為單位)。
isAtDocumentEnd()Boolean判斷元素是否位於 Document 的結尾。
merge()InlineImage將元素與前相同類型的同層級合併。
removeFromParent()InlineImage從父項中移除元素。
setAltDescription(description)InlineImage設定圖片的替代說明。
setAltTitle(title)InlineImage設定圖片的替代標題。
setAttributes(attributes)InlineImage設定元素的屬性。
setHeight(height)InlineImage設定圖片的高度 (以像素為單位)。
setLinkUrl(url)InlineImage設定連結網址。
setWidth(width)InlineImage設定圖片的寬度 (以像素為單位)。

內容詳盡的說明文件

copy()

傳回目前元素的卸離深層連結。

系統也會複製元素中的所有子元素。新元素沒有父項。

Return 鍵

InlineImage — 新副本。

授權

如果指令碼使用這個方法,就必須符合下列一或多個範圍的授權:

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

getAltDescription()

傳回圖片的替代說明。

Return 鍵

String:替代標題,如果元素沒有替代標題,則傳回 null

授權

如果指令碼使用這個方法,就必須符合下列一或多個範圍的授權:

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

getAltTitle()

傳回圖片的替代標題。

Return 鍵

String:替代標題,如果元素沒有替代標題,則傳回 null

授權

如果指令碼使用這個方法,就必須符合下列一或多個範圍的授權:

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

getAs(contentType)

傳回此物件中的資料,以轉換為指定內容類型的 blob。這個方法會在檔案名稱中加上適當的副檔名,例如「quofile;myfile.pdf"」。但其假設,最後一個月後面的檔案名稱部分 (如果有) 是必須取代的現有副檔名。因此「quoList;ShoppingList.12.25.2014"」將變成「ShoppingList.12.25.pdf"」。

如要查看轉換的每日配額,請參閱 Google 服務的配額。新建立的 Google Workspace 網域可能會暫時受到限制,

參數

名稱類型說明
contentTypeString要轉換的 MIME 類型。對大多數 blob 而言,'application/pdf' 是唯一有效的選項。如果圖片是 BMP、GIF、JPEG 或 PNG 格式,則 'image/bmp''image/gif''image/jpeg''image/png' 中任何一個都是有效的。

Return 鍵

Blob — 將資料以 blob 形式呈現。


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]);
}

Return 鍵

Object — 元素的屬性。

授權

如果指令碼使用這個方法,就必須符合下列一或多個範圍的授權:

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

getBlob()

傳回這個物件中的資料,以 blob 形式傳回。

Return 鍵

Blob — 將資料以 blob 形式呈現。


getHeight()

擷取圖片的高度 (以像素為單位)。

Return 鍵

Integer — 圖片的高度 (以像素為單位)

授權

如果指令碼使用這個方法,就必須符合下列一或多個範圍的授權:

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

getLinkUrl()

擷取連結網址。

Return 鍵

String:連結網址,如果元素包含多個屬性,則傳回 null

授權

如果指令碼使用這個方法,就必須符合下列一或多個範圍的授權:

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

getNextSibling()

擷取元素和下一個下一個同層級元素。

下一個同層級的父項相同,並沿用目前的元素。

Return 鍵

Element:下一個同層級元素。

授權

如果指令碼使用這個方法,就必須符合下列一或多個範圍的授權:

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

getParent()

擷取元素的父項元素。

父項元素包含目前元素。

Return 鍵

ContainerElement:父項元素。

授權

如果指令碼使用這個方法,就必須符合下列一或多個範圍的授權:

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

getPreviousSibling()

擷取該元素之前的同層級元素。

上一個同層級的父項相同,並加上目前元素。

Return 鍵

Element:上一個同層級元素。

授權

如果指令碼使用這個方法,就必須符合下列一或多個範圍的授權:

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

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.');
}

Return 鍵

ElementType:元素類型,

授權

如果指令碼使用這個方法,就必須符合下列一或多個範圍的授權:

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

getWidth()

擷取圖片的寬度 (以像素為單位)。

Return 鍵

Integer — 圖片的寬度 (以像素為單位)

授權

如果指令碼使用這個方法,就必須符合下列一或多個範圍的授權:

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

isAtDocumentEnd()

判斷元素是否位於 Document 的結尾。

Return 鍵

Boolean — 元素是否位於文件結尾。

授權

如果指令碼使用這個方法,就必須符合下列一或多個範圍的授權:

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

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

Return 鍵

InlineImage — 合併的元素。

授權

如果指令碼使用這個方法,就必須符合下列一或多個範圍的授權:

  • 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();
}

Return 鍵

InlineImage — 移除的元素。

授權

如果指令碼使用這個方法,就必須符合下列一或多個範圍的授權:

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

setAltDescription(description)

設定圖片的替代說明。如果指定的標題是 null,請將說明設為空白字串。

參數

名稱類型說明
descriptionString替代標題

Return 鍵

InlineImage:目前的物件

授權

如果指令碼使用這個方法,就必須符合下列一或多個範圍的授權:

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

setAltTitle(title)

設定圖片的替代標題。如果指定的標題是 null,請將標題設為空字串。

參數

名稱類型說明
titleString替代標題

Return 鍵

InlineImage:目前的物件

授權

如果指令碼使用這個方法,就必須符合下列一或多個範圍的授權:

  • 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);

參數

名稱類型說明
attributesObject元素的屬性。

Return 鍵

InlineImage — 目前的元素。

授權

如果指令碼使用這個方法,就必須符合下列一或多個範圍的授權:

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

setHeight(height)

設定圖片的高度 (以像素為單位)。

參數

名稱類型說明
heightInteger圖片的高度 (以像素為單位)

Return 鍵

InlineImage:目前的物件

授權

如果指令碼使用這個方法,就必須符合下列一或多個範圍的授權:

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

setLinkUrl(url)

設定連結網址。如果提供的網址是 null 或空字串,這個方法會建立連結,並在 Google 文件中顯示顯示為「無效連結」的空白網址。

參數

名稱類型說明
urlString連結網址。

Return 鍵

InlineImage:目前的物件

授權

如果指令碼使用這個方法,就必須符合下列一或多個範圍的授權:

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

setWidth(width)

設定圖片的寬度 (以像素為單位)。

參數

名稱類型說明
widthInteger圖片的寬度 (以像素為單位)

Return 鍵

InlineImage:目前的物件

授權

如果指令碼使用這個方法,就必須符合下列一或多個範圍的授權:

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