Class InlineImage

インライン画像

埋め込み画像を表す要素。ListItem または ParagraphFootnoteSection 内にある場合を除き、InlineImageListItem または Paragraph 内に含めることができます。InlineImage 自体には他の要素を含めることはできません。ドキュメント構造の詳細については、Google ドキュメントを拡張するためのガイドをご覧ください。

メソッド

メソッド戻り値の型概要
copy()InlineImage現在の要素の切り離されたディープコピーを返します。
getAltDescription()String画像の代替説明を返します。
getAltTitle()String画像の代替タイトルを返します。
getAs(contentType)Blobこのオブジェクト内のデータを、指定されたコンテンツ タイプに変換された blob として返します。
getAttributes()Object要素の属性を取得します。
getBlob()Blobこのオブジェクト内のデータを blob として返します。
getHeight()Integer画像の高さ(ピクセル単位)を取得します。
getLinkUrl()Stringリンク URL を取得します。
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リンクの URL を設定します。
setWidth(width)InlineImage画像の幅をピクセル単位で設定します。

詳細なドキュメント

copy()

現在の要素のデタッチされたディープコピーを返します。

要素に含まれる子要素もコピーされます。新しい要素には親がありません。

戻る

InlineImage - 新しいコピー。

承認

このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

getAltDescription()

画像の代替説明を返します。

戻る

String - 代替説明。要素に代替説明がない場合は null

承認

このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

getAltTitle()

画像の代替タイトルを返します。

戻る

String - 代替タイトル。要素に代替タイトルがない場合は null

承認

このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

getAs(contentType)

このオブジェクト内のデータを、指定されたコンテンツ タイプに変換された blob として返します。このメソッドは、ファイル名に適切な拡張子(「myfile.pdf」など)を追加します。ただし、最後のピリオドの後に続くファイル名の一部(存在する場合)は、置き換える必要がある既存の拡張子であると想定されます。その結果、「ShoppingList.12.25.2014」は「ShoppingList.12.25.pdf」になります。

コンバージョンの 1 日あたりの割り当てを確認するには、Google サービスの割り当てをご覧ください。新しく作成された Google Workspace ドメインには、一時的に厳しい割り当てが適用されることがあります。

パラメータ

名前説明
contentTypeString変換先の MIME タイプ。ほとんどの BLOB では、'application/pdf' が唯一の有効なオプションです。BMP、GIF、JPEG、PNG 形式の画像の場合、'image/bmp''image/gif''image/jpeg''image/png' のいずれも有効です。Google ドキュメントの場合、'text/markdown' も有効です。

戻る

Blob - BLOB としてのデータ。


getAttributes()

要素の属性を取得します。

結果は、有効な要素属性ごとにプロパティを含むオブジェクトです。各プロパティ名は 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]}`);
}

戻る

Object - 要素の属性。

承認

このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

getBlob()

このオブジェクト内のデータを blob として返します。

戻る

Blob - BLOB としてのデータ。


getHeight()

画像の高さ(ピクセル単位)を取得します。

戻る

Integer - 画像の高さ(ピクセル単位)

承認

このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

getLinkUrl()

リンク URL を取得します。

戻る

String - リンク URL。要素にこの属性の複数の値が含まれている場合は null

承認

このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

getNextSibling()

要素の次の兄弟要素を取得します。

次の兄弟要素は、同じ親を持ち、現在の要素の後に続きます。

戻る

Element - 次の兄弟要素。

承認

このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

getParent()

要素の親要素を取得します。

親要素に現在の要素が含まれている。

戻る

ContainerElement - 親要素。

承認

このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

getPreviousSibling()

要素の前の兄弟要素を取得します。

前の兄弟は同じ親を持ち、現在の要素の前にあります。

戻る

Element - 前の兄弟要素。

承認

このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

getType()

要素の ElementType を取得します。

getType() を使用して、特定の要素の正確な型を特定します。

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

戻る

ElementType - 要素のタイプ。

承認

このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

getWidth()

画像の幅(ピクセル単位)を取得します。

戻る

Integer - 画像の幅(ピクセル単位)

承認

このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

isAtDocumentEnd()

要素が Document の末尾にあるかどうかを判断します。

戻る

Boolean - 要素がタブの末尾にあるかどうか。

承認

このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

merge()

要素を同じタイプの前の兄弟要素とマージします。

統合できるのは、同じ ElementType の要素のみです。現在の要素に含まれる子要素は、前の兄弟要素に移動されます。

現在の要素がドキュメントから削除されます。

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

戻る

InlineImage - 結合された要素。

承認

このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

removeFromParent()

要素を親から削除します。

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

戻る

InlineImage - 削除された要素。

承認

このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

setAltDescription(description)

画像の代替説明を設定します。指定されたタイトルが null の場合、説明を空の文字列に設定します。

パラメータ

名前説明
descriptionString代替の説明。

戻る

InlineImage - 現在のオブジェクト。

承認

このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

setAltTitle(title)

画像の代替タイトルを設定します。指定されたタイトルが null の場合、タイトルを空の文字列に設定します。

パラメータ

名前説明
titleString代替タイトル。

戻る

InlineImage - 現在のオブジェクト。

承認

このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

setAttributes(attributes)

要素の属性を設定します。

指定された attributes パラメータは、各プロパティ名が DocumentApp.Attribute 列挙型のアイテムで、各プロパティ値が適用される新しい値であるオブジェクトでなければなりません。

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

パラメータ

名前説明
attributesObject要素の属性。

戻る

InlineImage - 現在の要素。

承認

このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

setHeight(height)

画像の高さ(ピクセル単位)を設定します。

パラメータ

名前説明
heightInteger画像の高さ(ピクセル単位)

戻る

InlineImage - 現在のオブジェクト

承認

このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

setLinkUrl(url)

リンクの URL を設定します。指定された URL が null または空の文字列の場合、このメソッドは空の URL を持つリンクを作成します。このリンクは Google ドキュメントで「無効なリンク」と表示されることがあります。

パラメータ

名前説明
urlStringリンク URL です。

戻る

InlineImage - 現在のオブジェクト。

承認

このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

setWidth(width)

画像の幅をピクセル単位で設定します。

パラメータ

名前説明
widthInteger画像の幅(ピクセル単位)

戻る

InlineImage - 現在のオブジェクト

承認

このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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