Class InlineImage

InlineImage

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

Methods

メソッド戻り値の型概要
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' のいずれかも有効です。

リターン

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

リターン

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() を使用します。

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 - 要素のタイプ。

承認

この方法を使用するスクリプトには、次の 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 の要素のみです。現在の要素に含まれるすべての子要素は、前の兄弟要素に移動します。

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

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

リターン

InlineImage - 結合された要素。

承認

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

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

リターン

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)

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

指定する 属性パラメータは、各プロパティ名が 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要素の属性。

リターン

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