Class InlineImage

インライン画像

埋め込み画像を表す要素。InlineImage は、ListItem または ParagraphFootnoteSection 内にある場合を除き、ListItem または 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」になります。

コンバージョンの日別割り当てを表示するには、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