Word.Body class

文書またはセクションの本文を表します。

Extends

注釈

[ API セット: WordApi 1.1 ]

プロパティ

contentControls

本文のリッチ テキスト コンテンツ コントロール オブジェクトのコレクションを取得します。

context

オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。

endnotes

本文の文末脚注のコレクションを取得します。

fields

本文内のフィールド オブジェクトのコレクションを取得します。

font

本文のテキスト形式を取得します。 これを使用して、フォント名、サイズ、色、その他のプロパティを取得して設定します。

footnotes

本文の脚注のコレクションを取得します。

inlinePictures

本文内の InlinePicture オブジェクトのコレクションを取得します。 コレクションにはフローティング イメージは含まれません。

lists

本文に含まれるリスト オブジェクトのコレクションを取得します。

paragraphs

本文内の段落オブジェクトのコレクションを取得します。

parentBody

本文の親の本文を取得します。 たとえば、テーブル セル本文の親本文にはヘッダーを指定できます。 ItemNotFound親本文がない場合は、エラーをスローします。

parentBodyOrNullObject

本文の親の本文を取得します。 たとえば、テーブル セル本文の親本文にはヘッダーを指定できます。 親本体がない場合、このメソッドは プロパティが に設定されたオブジェクトをisNullObjecttrue返します。 詳細については、「 *OrNullObject メソッドとプロパティ」を参照してください。

parentContentControl

本文を含むコンテンツ コントロールを取得します。 ItemNotFound親コンテンツ コントロールがない場合は、エラーをスローします。

parentContentControlOrNullObject

本文を含むコンテンツ コントロールを取得します。 親コンテンツ コントロールがない場合、このメソッドは プロパティが に設定されたオブジェクトをisNullObjecttrue返します。 詳細については、「 *OrNullObject メソッドとプロパティ」を参照してください。

parentSection

本文の親セクションを取得します。 ItemNotFound親セクションがない場合は、エラーをスローします。

parentSectionOrNullObject

本文の親セクションを取得します。 親セクションがない場合、このメソッドは プロパティが に設定されたオブジェクトをisNullObjecttrue返します。 詳細については、「 *OrNullObject メソッドとプロパティ」を参照してください。

style

本文のスタイル名を指定します。 カスタム スタイルとローカライズされたスタイルの名前には、このプロパティを使用します。 ロケール間で移植可能な組み込みスタイルを使用するには、"styleBuiltIn" プロパティを参照してください。

styleBuiltIn

本文の組み込みスタイル名を指定します。 ロケール間で移植可能な組み込みスタイルの場合は、このプロパティを使用します。 カスタム スタイルまたはローカライズされたスタイルの名前を使用するには、"style" プロパティを参照してください。

tables

本文に含まれるテーブル オブジェクトのコレクションを取得します。

text

本文のテキストを取得します。 insertText メソッドを使用して、テキストを挿入します。

type

本文の種類を取得します。 種類は、'MainDoc'、'Section'、'Header'、'Footer'、または 'TableCell' にできます。 WordAPIOnline 1.1 以降では、追加の型 'Footnote'、'Endnote'、および 'NoteItem' がサポートされています。

メソッド

clear()

本文オブジェクトの内容を消去します。 ユーザーは、消去された内容を元に戻す操作を実行できます。

getComments()

本文に関連付けられているコメントを取得します。

getContentControls(options)

本文で現在サポートされているコンテンツ コントロールを取得します。

getHtml()

body オブジェクトの HTML 表現を取得します。 Web ページまたは HTML ビューアーでレンダリングされた場合、書式設定は、ドキュメントの書式設定と完全に一致しませんが、近い形式になります。 このメソッドは、異なるプラットフォーム (Windows、Mac、web 上のWordなど) 上の同じドキュメントに対してまったく同じ HTML を返しません。 正確な忠実性、またはプラットフォーム間の整合性が必要な場合は、返された XML を使用 Body.getOoxml() して HTML に変換します。

getOoxml()

本文オブジェクトの OOXML (Office オープン XML) 表記を取得します。

getRange(rangeLocation)

範囲として、本文全体、あるいは本文の開始点または終了点を取得します。

getReviewedText(changeTrackingVersion)

ChangeTrackingVersion の選択に基づいて、レビューされたテキストを取得します。

getReviewedText(changeTrackingVersionString)

ChangeTrackingVersion の選択に基づいて、レビューされたテキストを取得します。

getTrackedChanges()

本文の TrackedChange オブジェクトのコレクションを取得します。

insertBreak(breakType, insertLocation)

メイン文書の指定した位置に、区切りを挿入します。

insertContentControl(contentControlType)

Body オブジェクトをコンテンツ コントロールでラップします。

insertFileFromBase64(base64File, insertLocation)

文書を本文の指定された位置に挿入します。

insertHtml(html, insertLocation)

指定した位置に HTML を挿入します。

insertInlinePictureFromBase64(base64EncodedImage, insertLocation)

画像を本文の指定された位置に挿入します。

insertOoxml(ooxml, insertLocation)

指定した位置に OOXML を挿入します。

insertParagraph(paragraphText, insertLocation)

指定した位置に、段落を挿入します。

insertTable(rowCount, columnCount, insertLocation, values)

指定した数の行と列を含むテーブルを挿入します。

insertText(text, insertLocation)

テキストを本文の指定された位置に挿入します。

load(options)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

load(propertyNames)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

load(propertyNamesAndPaths)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

search(searchText, searchOptions)

body オブジェクトのスコープで、指定した SearchOptions を使用して検索を実行します。 検索結果は、範囲オブジェクトのコレクションです。

select(selectionMode)

本文を選択し、その本文に Word の UI を移動します。

select(selectionModeString)

本文を選択し、その本文に Word の UI を移動します。

set(properties, options)

オブジェクトの複数のプロパティを同時に設定します。 適切なプロパティを持つプレーン オブジェクトまたは同じ型の別の API オブジェクトを渡すことができます。

set(properties)

既存の読み込まれたオブジェクトに基づいて、オブジェクトに複数のプロパティを同時に設定します。

toJSON()

API オブジェクトが に渡されたときにより便利な出力を提供するために、JavaScript toJSON() メソッドを JSON.stringify()オーバーライドします。 (JSON.stringifyさらに、渡される オブジェクトの メソッドを呼び出toJSONします)。一方、元のWord。Body オブジェクトは API オブジェクトです。メソッドは、元のtoJSONオブジェクトから読み込まれた子プロパティの浅いコピーを含むプレーンな JavaScript オブジェクト (としてWord.Interfaces.BodyData型指定) を返します。

track()

ドキュメントの環境変更に基づいて自動的に調整する目的でオブジェクトを追跡します。 この呼び出しは、context.trackedObjects.add(thisObject)の短縮形です。 このオブジェクトを呼び出しで .sync 使用していて、".run" バッチのシーケンシャル実行の外部で使用していて、プロパティを設定するとき、またはオブジェクトのメソッドを呼び出すときに "InvalidObjectPath" エラーが発生する場合は、オブジェクトが最初に作成されたときに追跡対象のオブジェクト コレクションにオブジェクトを追加する必要があります。 このオブジェクトがコレクションの一部である場合は、親コレクションも追跡する必要があります。

untrack()

前に追跡されていた場合、このオブジェクトに関連付けられているメモリを解放します。 この呼び出しは、context.trackedObjects.remove(thisObject)の短縮形です。 追跡対象オブジェクトが多いとホスト アプリケーションの動作が遅くなります。追加したオブジェクトが不要になったら、必ずそれを解放してください。 メモリ解放が有効になる前に を呼び出す context.sync() 必要があります。

イベント

onCommentAdded

新しいコメントが追加されたときに発生します。

onCommentChanged

コメントまたはその応答が変更されたときに発生します。

onCommentDeleted

コメントが削除されたときに発生します。

onCommentDeselected

コメントの選択が解除されたときに発生します。

onCommentSelected

コメントが選択されたときに発生します。

プロパティの詳細

contentControls

本文のリッチ テキスト コンテンツ コントロール オブジェクトのコレクションを取得します。

readonly contentControls: Word.ContentControlCollection;

プロパティ値

注釈

[ API セット: WordApi 1.1 ]

context

オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。

context: RequestContext;

プロパティ値

endnotes

本文の文末脚注のコレクションを取得します。

readonly endnotes: Word.NoteItemCollection;

プロパティ値

注釈

[ API セット: WordApi 1.5 ]

fields

本文内のフィールド オブジェクトのコレクションを取得します。

readonly fields: Word.FieldCollection;

プロパティ値

注釈

[ API セット: WordApi 1.4 ]

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-fields.yaml

// Gets all fields in the document body.
await Word.run(async (context) => {
  const fields = context.document.body.fields.load("items");

  await context.sync();

  if (fields.items.length === 0) {
    console.log("No fields in this document.");
  } else {
    fields.load(["code", "result"]);
    await context.sync();

    for (let i = 0; i < fields.items.length; i++) {
      console.log(`Field ${i + 1}'s code: ${fields.items[i].code}`);
      console.log(`Field ${i + 1}'s result: ${JSON.stringify(fields.items[i].result)}`);
    }
  }
});

font

本文のテキスト形式を取得します。 これを使用して、フォント名、サイズ、色、その他のプロパティを取得して設定します。

readonly font: Word.Font;

プロパティ値

注釈

[ API セット: WordApi 1.1 ]

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-body.yaml

// Gets the style and the font size, font name, and font color properties on the body object.
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
  // Create a proxy object for the document body.
  const body = context.document.body;

  // Queue a command to load font and style information for the document body.
  body.load("font/size, font/name, font/color, style");

  // Synchronize the document state by executing the queued commands, and return a promise to indicate task completion.
  await context.sync();

  // Show font-related property values on the body object.
  const results =
    "Font size: " +
    body.font.size +
    "; Font name: " +
    body.font.name +
    "; Font color: " +
    body.font.color +
    "; Body style: " +
    body.style;

  console.log(results);
});

footnotes

本文の脚注のコレクションを取得します。

readonly footnotes: Word.NoteItemCollection;

プロパティ値

注釈

[ API セット: WordApi 1.5 ]

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-footnotes.yaml

// Gets the footnotes in the document body.
await Word.run(async (context) => {
  const footnotes = context.document.body.footnotes;
  footnotes.load("length");
  await context.sync();

  console.log("Number of footnotes in the document body: " + footnotes.items.length);
});

inlinePictures

本文内の InlinePicture オブジェクトのコレクションを取得します。 コレクションにはフローティング イメージは含まれません。

readonly inlinePictures: Word.InlinePictureCollection;

プロパティ値

注釈

[ API セット: WordApi 1.1 ]

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/15-images/insert-and-get-pictures.yaml

// Gets the first image in the document.
await Word.run(async (context) => {
  const firstPicture = context.document.body.inlinePictures.getFirst();
  firstPicture.load("width, height");

  await context.sync();
  console.log(`Image dimensions: ${firstPicture.width} x ${firstPicture.height}`);
  // Get the image encoded as Base64.
  const base64 = firstPicture.getBase64ImageSrc();

  await context.sync();
  console.log(base64.value);
});

lists

本文に含まれるリスト オブジェクトのコレクションを取得します。

readonly lists: Word.ListCollection;

プロパティ値

注釈

[ API セット: WordApi 1.3 ]

paragraphs

本文内の段落オブジェクトのコレクションを取得します。

readonly paragraphs: Word.ParagraphCollection;

プロパティ値

注釈

[ API セット: WordApi 1.1 ]

重要: 要件セット 1.1 と 1.2 では、テーブル内の段落は返されません。 要件セット 1.3 から、テーブル内の段落も返されます。

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/25-paragraph/get-word-count.yaml

// Counts how many times each term appears in the document.
await Word.run(async (context) => {
  const paragraphs = context.document.body.paragraphs;
  paragraphs.load("text");
  await context.sync();

  // Split up the document text using existing spaces as the delimiter.
  let text = [];
  paragraphs.items.forEach((item) => {
    let paragraph = item.text.trim();
    if (paragraph) {
      paragraph.split(" ").forEach((term) => {
        let currentTerm = term.trim();
        if (currentTerm) {
          text.push(currentTerm);
        }
      });
    }
  });

  // Determine the list of unique terms.
  let makeTextDistinct = new Set(text);
  let distinctText = Array.from(makeTextDistinct);
  let allSearchResults = [];

  for (let i = 0; i < distinctText.length; i++) {
    let results = context.document.body.search(distinctText[i], { matchCase: true, matchWholeWord: true });
    results.load("text");

    // Map each search term with its results.
    let correlatedResults = {
      searchTerm: distinctText[i],
      hits: results
    };

    allSearchResults.push(correlatedResults);
  }

  await context.sync();

  // Display the count for each search term.
  allSearchResults.forEach((result) => {
    let length = result.hits.items.length;

    console.log("Search term: " + result.searchTerm + " => Count: " + length);
  });
});

parentBody

本文の親の本文を取得します。 たとえば、テーブル セル本文の親本文にはヘッダーを指定できます。 ItemNotFound親本文がない場合は、エラーをスローします。

readonly parentBody: Word.Body;

プロパティ値

注釈

[ API セット: WordApi 1.3 ]

parentBodyOrNullObject

本文の親の本文を取得します。 たとえば、テーブル セル本文の親本文にはヘッダーを指定できます。 親本体がない場合、このメソッドは プロパティが に設定されたオブジェクトをisNullObjecttrue返します。 詳細については、「 *OrNullObject メソッドとプロパティ」を参照してください。

readonly parentBodyOrNullObject: Word.Body;

プロパティ値

注釈

[ API セット: WordApi 1.3 ]

parentContentControl

本文を含むコンテンツ コントロールを取得します。 ItemNotFound親コンテンツ コントロールがない場合は、エラーをスローします。

readonly parentContentControl: Word.ContentControl;

プロパティ値

注釈

[ API セット: WordApi 1.1 ]

parentContentControlOrNullObject

本文を含むコンテンツ コントロールを取得します。 親コンテンツ コントロールがない場合、このメソッドは プロパティが に設定されたオブジェクトをisNullObjecttrue返します。 詳細については、「 *OrNullObject メソッドとプロパティ」を参照してください。

readonly parentContentControlOrNullObject: Word.ContentControl;

プロパティ値

注釈

[ API セット: WordApi 1.3 ]

parentSection

本文の親セクションを取得します。 ItemNotFound親セクションがない場合は、エラーをスローします。

readonly parentSection: Word.Section;

プロパティ値

注釈

[ API セット: WordApi 1.3 ]

parentSectionOrNullObject

本文の親セクションを取得します。 親セクションがない場合、このメソッドは プロパティが に設定されたオブジェクトをisNullObjecttrue返します。 詳細については、「 *OrNullObject メソッドとプロパティ」を参照してください。

readonly parentSectionOrNullObject: Word.Section;

プロパティ値

注釈

[ API セット: WordApi 1.3 ]

style

本文のスタイル名を指定します。 カスタム スタイルとローカライズされたスタイルの名前には、このプロパティを使用します。 ロケール間で移植可能な組み込みスタイルを使用するには、"styleBuiltIn" プロパティを参照してください。

style: string;

プロパティ値

string

注釈

[ API セット: WordApi 1.1 ]

styleBuiltIn

本文の組み込みスタイル名を指定します。 ロケール間で移植可能な組み込みスタイルの場合は、このプロパティを使用します。 カスタム スタイルまたはローカライズされたスタイルの名前を使用するには、"style" プロパティを参照してください。

styleBuiltIn: Word.BuiltInStyleName | "Other" | "Normal" | "Heading1" | "Heading2" | "Heading3" | "Heading4" | "Heading5" | "Heading6" | "Heading7" | "Heading8" | "Heading9" | "Toc1" | "Toc2" | "Toc3" | "Toc4" | "Toc5" | "Toc6" | "Toc7" | "Toc8" | "Toc9" | "FootnoteText" | "Header" | "Footer" | "Caption" | "FootnoteReference" | "EndnoteReference" | "EndnoteText" | "Title" | "Subtitle" | "Hyperlink" | "Strong" | "Emphasis" | "NoSpacing" | "ListParagraph" | "Quote" | "IntenseQuote" | "SubtleEmphasis" | "IntenseEmphasis" | "SubtleReference" | "IntenseReference" | "BookTitle" | "Bibliography" | "TocHeading" | "TableGrid" | "PlainTable1" | "PlainTable2" | "PlainTable3" | "PlainTable4" | "PlainTable5" | "TableGridLight" | "GridTable1Light" | "GridTable1Light_Accent1" | "GridTable1Light_Accent2" | "GridTable1Light_Accent3" | "GridTable1Light_Accent4" | "GridTable1Light_Accent5" | "GridTable1Light_Accent6" | "GridTable2" | "GridTable2_Accent1" | "GridTable2_Accent2" | "GridTable2_Accent3" | "GridTable2_Accent4" | "GridTable2_Accent5" | "GridTable2_Accent6" | "GridTable3" | "GridTable3_Accent1" | "GridTable3_Accent2" | "GridTable3_Accent3" | "GridTable3_Accent4" | "GridTable3_Accent5" | "GridTable3_Accent6" | "GridTable4" | "GridTable4_Accent1" | "GridTable4_Accent2" | "GridTable4_Accent3" | "GridTable4_Accent4" | "GridTable4_Accent5" | "GridTable4_Accent6" | "GridTable5Dark" | "GridTable5Dark_Accent1" | "GridTable5Dark_Accent2" | "GridTable5Dark_Accent3" | "GridTable5Dark_Accent4" | "GridTable5Dark_Accent5" | "GridTable5Dark_Accent6" | "GridTable6Colorful" | "GridTable6Colorful_Accent1" | "GridTable6Colorful_Accent2" | "GridTable6Colorful_Accent3" | "GridTable6Colorful_Accent4" | "GridTable6Colorful_Accent5" | "GridTable6Colorful_Accent6" | "GridTable7Colorful" | "GridTable7Colorful_Accent1" | "GridTable7Colorful_Accent2" | "GridTable7Colorful_Accent3" | "GridTable7Colorful_Accent4" | "GridTable7Colorful_Accent5" | "GridTable7Colorful_Accent6" | "ListTable1Light" | "ListTable1Light_Accent1" | "ListTable1Light_Accent2" | "ListTable1Light_Accent3" | "ListTable1Light_Accent4" | "ListTable1Light_Accent5" | "ListTable1Light_Accent6" | "ListTable2" | "ListTable2_Accent1" | "ListTable2_Accent2" | "ListTable2_Accent3" | "ListTable2_Accent4" | "ListTable2_Accent5" | "ListTable2_Accent6" | "ListTable3" | "ListTable3_Accent1" | "ListTable3_Accent2" | "ListTable3_Accent3" | "ListTable3_Accent4" | "ListTable3_Accent5" | "ListTable3_Accent6" | "ListTable4" | "ListTable4_Accent1" | "ListTable4_Accent2" | "ListTable4_Accent3" | "ListTable4_Accent4" | "ListTable4_Accent5" | "ListTable4_Accent6" | "ListTable5Dark" | "ListTable5Dark_Accent1" | "ListTable5Dark_Accent2" | "ListTable5Dark_Accent3" | "ListTable5Dark_Accent4" | "ListTable5Dark_Accent5" | "ListTable5Dark_Accent6" | "ListTable6Colorful" | "ListTable6Colorful_Accent1" | "ListTable6Colorful_Accent2" | "ListTable6Colorful_Accent3" | "ListTable6Colorful_Accent4" | "ListTable6Colorful_Accent5" | "ListTable6Colorful_Accent6" | "ListTable7Colorful" | "ListTable7Colorful_Accent1" | "ListTable7Colorful_Accent2" | "ListTable7Colorful_Accent3" | "ListTable7Colorful_Accent4" | "ListTable7Colorful_Accent5" | "ListTable7Colorful_Accent6";

プロパティ値

Word.BuiltInStyleName | "Other" | "Normal" | "Heading1" | "Heading2" | "Heading3" | "Heading4" | "Heading5" | "Heading6" | "Heading7" | "Heading8" | "Heading9" | "Toc1" | "Toc2" | "Toc3" | "Toc4" | "Toc5" | "Toc6" | "Toc7" | "Toc8" | "Toc9" | "FootnoteText" | "Header" | "Footer" | "Caption" | "FootnoteReference" | "EndnoteReference" | "EndnoteText" | "Title" | "Subtitle" | "Hyperlink" | "Strong" | "Emphasis" | "NoSpacing" | "ListParagraph" | "Quote" | "IntenseQuote" | "SubtleEmphasis" | "IntenseEmphasis" | "SubtleReference" | "IntenseReference" | "BookTitle" | "Bibliography" | "TocHeading" | "TableGrid" | "PlainTable1" | "PlainTable2" | "PlainTable3" | "PlainTable4" | "PlainTable5" | "TableGridLight" | "GridTable1Light" | "GridTable1Light_Accent1" | "GridTable1Light_Accent2" | "GridTable1Light_Accent3" | "GridTable1Light_Accent4" | "GridTable1Light_Accent5" | "GridTable1Light_Accent6" | "GridTable2" | "GridTable2_Accent1" | "GridTable2_Accent2" | "GridTable2_Accent3" | "GridTable2_Accent4" | "GridTable2_Accent5" | "GridTable2_Accent6" | "GridTable3" | "GridTable3_Accent1" | "GridTable3_Accent2" | "GridTable3_Accent3" | "GridTable3_Accent4" | "GridTable3_Accent5" | "GridTable3_Accent6" | "GridTable4" | "GridTable4_Accent1" | "GridTable4_Accent2" | "GridTable4_Accent3" | "GridTable4_Accent4" | "GridTable4_Accent5" | "GridTable4_Accent6" | "GridTable5Dark" | "GridTable5Dark_Accent1" | "GridTable5Dark_Accent2" | "GridTable5Dark_Accent3" | "GridTable5Dark_Accent4" | "GridTable5Dark_Accent5" | "GridTable5Dark_Accent6" | "GridTable6Colorful" | "GridTable6Colorful_Accent1" | "GridTable6Colorful_Accent2" | "GridTable6Colorful_Accent3" | "GridTable6Colorful_Accent4" | "GridTable6Colorful_Accent5" | "GridTable6Colorful_Accent6" | "GridTable7Colorful" | "GridTable7Colorful_Accent1" | "GridTable7Colorful_Accent2" | "GridTable7Colorful_Accent3" | "GridTable7Colorful_Accent4" | "GridTable7Colorful_Accent5" | "GridTable7Colorful_Accent6" | "ListTable1Light" | "ListTable1Light_Accent1" | "ListTable1Light_Accent2" | "ListTable1Light_Accent3" | "ListTable1Light_Accent4" | "ListTable1Light_Accent5" | "ListTable1Light_Accent6" | "ListTable2" | "ListTable2_Accent1" | "ListTable2_Accent2" | "ListTable2_Accent3" | "ListTable2_Accent4" | "ListTable2_Accent5" | "ListTable2_Accent6" | "ListTable3" | "ListTable3_Accent1" | "ListTable3_Accent2" | "ListTable3_Accent3" | "ListTable3_Accent4" | "ListTable3_Accent5" | "ListTable3_Accent6" | "ListTable4" | "ListTable4_Accent1" | "ListTable4_Accent2" | "ListTable4_Accent3" | "ListTable4_Accent4" | "ListTable4_Accent5" | "ListTable4_Accent6" | "ListTable5Dark" | "ListTable5Dark_Accent1" | "ListTable5Dark_Accent2" | "ListTable5Dark_Accent3" | "ListTable5Dark_Accent4" | "ListTable5Dark_Accent5" | "ListTable5Dark_Accent6" | "ListTable6Colorful" | "ListTable6Colorful_Accent1" | "ListTable6Colorful_Accent2" | "ListTable6Colorful_Accent3" | "ListTable6Colorful_Accent4" | "ListTable6Colorful_Accent5" | "ListTable6Colorful_Accent6" | "ListTable7Colorful" | "ListTable7Colorful_Accent1" | "ListTable7Colorful_Accent2" | "ListTable7Colorful_Accent3" | "ListTable7Colorful_Accent4" | "ListTable7Colorful_Accent5" | "ListTable7Colorful_Accent6"

注釈

[ API セット: WordApi 1.3 ]

tables

本文に含まれるテーブル オブジェクトのコレクションを取得します。

readonly tables: Word.TableCollection;

プロパティ値

注釈

[ API セット: WordApi 1.3 ]

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/40-tables/table-cell-access.yaml

// Gets the content of the first cell in the first table.
await Word.run(async (context) => {
  const firstCell = context.document.body.tables.getFirst().getCell(0, 0).body;
  firstCell.load("text");

  await context.sync();
  console.log("First cell's text is: " + firstCell.text);
});

text

本文のテキストを取得します。 insertText メソッドを使用して、テキストを挿入します。

readonly text: string;

プロパティ値

string

注釈

[ API セット: WordApi 1.1 ]

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-body.yaml

// Gets the text content of the body.
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
  // Create a proxy object for the document body.
  const body = context.document.body;

  // Queue a command to load the text in document body.
  body.load("text");

  // Synchronize the document state by executing the queued commands, and return a promise to indicate task completion.
  await context.sync();

  console.log("Body contents (text): " + body.text);
});

type

本文の種類を取得します。 種類は、'MainDoc'、'Section'、'Header'、'Footer'、または 'TableCell' にできます。 WordAPIOnline 1.1 以降では、追加の型 'Footnote'、'Endnote'、および 'NoteItem' がサポートされています。

readonly type: Word.BodyType | "Unknown" | "MainDoc" | "Section" | "Header" | "Footer" | "TableCell" | "Footnote" | "Endnote" | "NoteItem";

プロパティ値

Word.BodyType | "Unknown" | "MainDoc" | "Section" | "Header" | "Footer" | "TableCell" | "Footnote" | "Endnote" | "NoteItem"

注釈

[ API セット: WordApi 1.3 ]

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-footnotes.yaml

// Gets the referenced note's item type and body type, which are both "Footnote".
await Word.run(async (context) => {
  const footnotes = context.document.body.footnotes;
  footnotes.load("items");
  await context.sync();

  const referenceNumber = $("#input-reference").val();
  const mark = (referenceNumber as number) - 1;
  const item = footnotes.items[mark];
  console.log(`Note type of footnote ${referenceNumber}: ${item.type}`);

  item.body.load("type");
  await context.sync();

  console.log(`Body type of note: ${item.body.type}`);
});

メソッドの詳細

clear()

本文オブジェクトの内容を消去します。 ユーザーは、消去された内容を元に戻す操作を実行できます。

clear(): void;

戻り値

void

注釈

[ API セット: WordApi 1.1 ]

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-body.yaml

// Clears out the content from the document body.
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
  // Create a proxy object for the document body.
  const body = context.document.body;

  // Queue a command to clear the contents of the body.
  body.clear();

  console.log("Cleared the body contents.");
});

// The Silly stories add-in sample shows how the clear method can be used to clear the contents of a document.
// https://aka.ms/sillystorywordaddin

getComments()

本文に関連付けられているコメントを取得します。

getComments(): Word.CommentCollection;

戻り値

注釈

[ API セット: WordApi 1.4 ]

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-comments.yaml

// Gets the comments in the document body.
await Word.run(async (context) => {
  const comments = context.document.body.getComments();

  // Load objects for display in Script Lab console.
  comments.load();
  await context.sync();

  console.log("All comments:");
  console.log(comments);
});

getContentControls(options)

本文で現在サポートされているコンテンツ コントロールを取得します。

getContentControls(options?: Word.ContentControlOptions): Word.ContentControlCollection;

パラメーター

options
Word.ContentControlOptions

オプション。 返されるコンテンツ コントロールを定義するオプション。

戻り値

注釈

[ API セット: WordApi 1.5 ]

重要: options パラメーターに特定の型が指定されている場合、サポートされている型のコンテンツ コントロールのみが返されます。 ジェネリック Wordのメソッドを使用すると、例外がスローされることに注意してください特定の種類に関連しない ContentControl。 時間によっては、追加の種類のコンテンツ コントロールがサポートされる場合があります。 そのため、アドインは特定の種類のコンテンツ コントロールを要求して処理する必要があります。

getHtml()

body オブジェクトの HTML 表現を取得します。 Web ページまたは HTML ビューアーでレンダリングされた場合、書式設定は、ドキュメントの書式設定と完全に一致しませんが、近い形式になります。 このメソッドは、異なるプラットフォーム (Windows、Mac、web 上のWordなど) 上の同じドキュメントに対してまったく同じ HTML を返しません。 正確な忠実性、またはプラットフォーム間の整合性が必要な場合は、返された XML を使用 Body.getOoxml() して HTML に変換します。

getHtml(): OfficeExtension.ClientResult<string>;

戻り値

注釈

[ API セット: WordApi 1.1 ]

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-body.yaml

// Gets the HTML that represents the content of the body.
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
  // Create a proxy object for the document body.
  const body = context.document.body;

  // Queue a command to get the HTML contents of the body.
  const bodyHTML = body.getHtml();

  // Synchronize the document state by executing the queued commands, and return a promise to indicate task completion.
  await context.sync();

  console.log("Body contents (HTML): " + bodyHTML.value);
});

getOoxml()

本文オブジェクトの OOXML (Office オープン XML) 表記を取得します。

getOoxml(): OfficeExtension.ClientResult<string>;

戻り値

注釈

[ API セット: WordApi 1.1 ]

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-body.yaml

// Gets the OOXML that represents the content of the body.
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
  // Create a proxy object for the document body.
  const body = context.document.body;

  // Queue a command to get the OOXML contents of the body.
  const bodyOOXML = body.getOoxml();

  // Synchronize the document state by executing the queued commands, and return a promise to indicate task completion.
  await context.sync();

  console.log("Body contents (OOXML): " + bodyOOXML.value);
});

getRange(rangeLocation)

範囲として、本文全体、あるいは本文の開始点または終了点を取得します。

getRange(rangeLocation?: Word.RangeLocation.whole | Word.RangeLocation.start | Word.RangeLocation.end | Word.RangeLocation.after | Word.RangeLocation.content | "Whole" | "Start" | "End" | "After" | "Content"): Word.Range;

パラメーター

rangeLocation

whole | start | end | after | content | "Whole" | "Start" | "End" | "After" | "Content"

オプション。 範囲の場所は、'Whole'、'Start'、'End'、'After'、または 'Content' である必要があります。

戻り値

注釈

[ API セット: WordApi 1.3 ]

getReviewedText(changeTrackingVersion)

ChangeTrackingVersion の選択に基づいて、レビューされたテキストを取得します。

getReviewedText(changeTrackingVersion?: Word.ChangeTrackingVersion): OfficeExtension.ClientResult<string>;

パラメーター

changeTrackingVersion
Word.ChangeTrackingVersion

オプション。 値は 'Original' または 'Current' である必要があります。 既定値は 'Current' です。

戻り値

注釈

[ API セット: WordApi 1.4 ]

getReviewedText(changeTrackingVersionString)

ChangeTrackingVersion の選択に基づいて、レビューされたテキストを取得します。

getReviewedText(changeTrackingVersionString?: "Original" | "Current"): OfficeExtension.ClientResult<string>;

パラメーター

changeTrackingVersionString

"Original" | "Current"

オプション。 値は 'Original' または 'Current' である必要があります。 既定値は 'Current' です。

戻り値

注釈

[ API セット: WordApi 1.4 ]

getTrackedChanges()

本文の TrackedChange オブジェクトのコレクションを取得します。

getTrackedChanges(): Word.TrackedChangeCollection;

戻り値

注釈

[ API セット: WordApi 1.6 ]

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-tracked-changes.yaml

// Gets all tracked changes.
await Word.run(async (context) => {
  const body = context.document.body;
  const trackedChanges = body.getTrackedChanges();
  trackedChanges.load();
  await context.sync();

  console.log(trackedChanges);
});

insertBreak(breakType, insertLocation)

メイン文書の指定した位置に、区切りを挿入します。

insertBreak(breakType: Word.BreakType | "Page" | "Next" | "SectionNext" | "SectionContinuous" | "SectionEven" | "SectionOdd" | "Line", insertLocation: Word.InsertLocation.start | Word.InsertLocation.end | "Start" | "End"): void;

パラメーター

breakType

Word.BreakType | "Page" | "Next" | "SectionNext" | "SectionContinuous" | "SectionEven" | "SectionOdd" | "Line"

必須です。 本文に追加する区切りの種類。

insertLocation

start | end | "Start" | "End"

必須です。 値は 'Start' または 'End' である必要があります。

戻り値

void

注釈

[ API セット: WordApi 1.1 ]

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-body.yaml

// Inserts a page break at the beginning of the document.
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
  // Create a proxy object for the document body.
  const body = context.document.body;

  // Queue a command to insert a page break at the start of the document body.
  body.insertBreak(Word.BreakType.page, Word.InsertLocation.start);

  // Synchronize the document state by executing the queued commands, and return a promise to indicate task completion.
  await context.sync();

  console.log("Added a page break at the start of the document body.");
});

insertContentControl(contentControlType)

Body オブジェクトをコンテンツ コントロールでラップします。

insertContentControl(contentControlType?: Word.ContentControlType.richText | Word.ContentControlType.plainText | Word.ContentControlType.checkBox | "RichText" | "PlainText" | "CheckBox"): Word.ContentControl;

パラメーター

contentControlType

richText | plainText | checkBox | "RichText" | "PlainText" | "CheckBox"

オプション。 挿入するコンテンツ コントロールの種類。 'RichText'、'PlainText'、または 'CheckBox' である必要があります。 既定値は "RichText" です。

戻り値

注釈

[ API セット: WordApi 1.1 ]

注: パラメーターは contentControlType WordApi 1.5 で導入されました。 PlainText WordApi 1.5 でサポートが追加されました。 CheckBox WordApi 1.7 でサポートが追加されました。

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-body.yaml

// Creates a content control using the document body.
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
  // Create a proxy object for the document body.
  const body = context.document.body;

  // Queue a command to wrap the body in a content control.
  body.insertContentControl();

  // Synchronize the document state by executing the queued commands, and return a promise to indicate task completion.
  await context.sync();

  console.log("Wrapped the body in a content control.");
});

insertFileFromBase64(base64File, insertLocation)

文書を本文の指定された位置に挿入します。

insertFileFromBase64(base64File: string, insertLocation: Word.InsertLocation.replace | Word.InsertLocation.start | Word.InsertLocation.end | "Replace" | "Start" | "End"): Word.Range;

パラメーター

base64File

string

必須です。 .docx ファイルの Base64 でエンコードされたコンテンツ。

insertLocation

replace | start | end | "Replace" | "Start" | "End"

必須です。 値は、'Replace'、'Start'、または 'End' である必要があります。

戻り値

注釈

[ API セット: WordApi 1.1 ]

注: 挿入するドキュメントに ActiveX コントロールが含まれている場合 (フォーム フィールドの可能性があります)、挿入はサポートされません。 このようなフォーム フィールドを、シナリオに適したコンテンツ コントロールまたはその他のオプションに置き換えることを検討してください。

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-body.yaml

// Inserts the body from the external document at the beginning of this document.
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
  // Create a proxy object for the document body.
  const body = context.document.body;

  // Queue a command to insert the Base64-encoded string representation of the body of the selected .docx file at the beginning of the current document.
  body.insertFileFromBase64(externalDocument, Word.InsertLocation.start);

  // Synchronize the document state by executing the queued commands, and return a promise to indicate task completion.
  await context.sync();

  console.log("Added Base64-encoded text to the beginning of the document body.");
});

insertHtml(html, insertLocation)

指定した位置に HTML を挿入します。

insertHtml(html: string, insertLocation: Word.InsertLocation.replace | Word.InsertLocation.start | Word.InsertLocation.end | "Replace" | "Start" | "End"): Word.Range;

パラメーター

html

string

必須です。 文書に挿入する HTML。

insertLocation

replace | start | end | "Replace" | "Start" | "End"

必須です。 値は、'Replace'、'Start'、または 'End' である必要があります。

戻り値

注釈

[ API セット: WordApi 1.1 ]

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-body.yaml

// Inserts the HTML at the beginning of this document.
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
  // Create a proxy object for the document body.
  const body = context.document.body;

  // Queue a command to insert HTML at the beginning of the document.
  body.insertHtml("<strong>This is text inserted with body.insertHtml()</strong>", Word.InsertLocation.start);

  // Synchronize the document state by executing the queued commands, and return a promise to indicate task completion.
  await context.sync();

  console.log("HTML added to the beginning of the document body.");
});

insertInlinePictureFromBase64(base64EncodedImage, insertLocation)

画像を本文の指定された位置に挿入します。

insertInlinePictureFromBase64(base64EncodedImage: string, insertLocation: Word.InsertLocation.start | Word.InsertLocation.end | "Start" | "End"): Word.InlinePicture;

パラメーター

base64EncodedImage

string

必須です。 本文に挿入する Base64 でエンコードされたイメージ。

insertLocation

start | end | "Start" | "End"

必須です。 値は 'Start' または 'End' である必要があります。

戻り値

注釈

[ API セット: WordApi 1.2 ]

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-body.yaml

// Inserts an image inline at the beginning of this document.
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
  // Create a proxy object for the document body.
  const body = context.document.body;

  // Base64-encoded image to insert inline.
  const base64EncodedImg =
    "iVBORw0KGgoAAAANSUhEUgAAAB4AAAANCAIAAAAxEEnAAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACFSURBVDhPtY1BEoQwDMP6/0+XgIMTBAeYoTqso9Rkx1zG+tNj1H94jgGzeNSjteO5vtQQuG2seO0av8LzGbe3anzRoJ4ybm/VeKEerAEbAUpW4aWQCmrGFWykRzGBCnYy2ha3oAIq2MloW9yCCqhgJ6NtcQsqoIKdjLbFLaiACnYyf2fODbrjZcXfr2F4AAAAAElFTkSuQmCC";

  // Queue a command to insert a Base64-encoded image at the beginning of the current document.
  body.insertInlinePictureFromBase64(base64EncodedImg, Word.InsertLocation.start);

  // Synchronize the document state by executing the queued commands, and return a promise to indicate task completion.
  await context.sync();

  console.log("Added a Base64-encoded image to the beginning of the document body.");
});

insertOoxml(ooxml, insertLocation)

指定した位置に OOXML を挿入します。

insertOoxml(ooxml: string, insertLocation: Word.InsertLocation.replace | Word.InsertLocation.start | Word.InsertLocation.end | "Replace" | "Start" | "End"): Word.Range;

パラメーター

ooxml

string

必須です。 挿入する OOXML を指定します。

insertLocation

replace | start | end | "Replace" | "Start" | "End"

必須です。 値は、'Replace'、'Start'、または 'End' である必要があります。

戻り値

注釈

[ API セット: WordApi 1.1 ]

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-body.yaml

// Inserts OOXML at the beginning of this document.
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
  // Create a proxy object for the document body.
  const body = context.document.body;

  // Queue a command to insert OOXML at the beginning of the body.
  body.insertOoxml(
    "<pkg:package xmlns:pkg='http://schemas.microsoft.com/office/2006/xmlPackage'><pkg:part pkg:name='/_rels/.rels' pkg:contentType='application/vnd.openxmlformats-package.relationships+xml' pkg:padding='512'><pkg:xmlData><Relationships xmlns='http://schemas.openxmlformats.org/package/2006/relationships'><Relationship Id='rId1' Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument' Target='word/document.xml'/></Relationships></pkg:xmlData></pkg:part><pkg:part pkg:name='/word/document.xml' pkg:contentType='application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml'><pkg:xmlData><w:document xmlns:w='http://schemas.openxmlformats.org/wordprocessingml/2006/main' ><w:body><w:p><w:pPr><w:spacing w:before='360' w:after='0' w:line='480' w:lineRule='auto'/><w:rPr><w:color w:val='70AD47' w:themeColor='accent6'/><w:sz w:val='28'/></w:rPr></w:pPr><w:r><w:rPr><w:color w:val='70AD47' w:themeColor='accent6'/><w:sz w:val='28'/></w:rPr><w:t>This text has formatting directly applied to achieve its font size, color, line spacing, and paragraph spacing.</w:t></w:r></w:p></w:body></w:document></pkg:xmlData></pkg:part></pkg:package>",
    Word.InsertLocation.start
  );

  // Synchronize the document state by executing the queued commands, and return a promise to indicate task completion.
  await context.sync();

  console.log("Added OOXML to the beginning of the document body.");
});

// Read "Understand when and how to use Office Open XML in your Word add-in" for guidance on working with OOXML.
// https://learn.microsoft.com/office/dev/add-ins/word/create-better-add-ins-for-word-with-office-open-xml

// The Word-Add-in-DocumentAssembly sample shows how you can use this API to assemble a document.
// https://github.com/OfficeDev/Word-Add-in-DocumentAssembly

insertParagraph(paragraphText, insertLocation)

指定した位置に、段落を挿入します。

insertParagraph(paragraphText: string, insertLocation: Word.InsertLocation.start | Word.InsertLocation.end | "Start" | "End"): Word.Paragraph;

パラメーター

paragraphText

string

必須です。 挿入する段落テキスト。

insertLocation

start | end | "Start" | "End"

必須です。 値は 'Start' または 'End' である必要があります。

戻り値

注釈

[ API セット: WordApi 1.1 ]

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/25-paragraph/insert-formatted-text.yaml

await Word.run(async (context) => {
  // Second sentence, let's insert it as a paragraph after the previously inserted one.
  const secondSentence = context.document.body.insertParagraph(
    "This is the first text with a custom style.",
    "End"
  );
  secondSentence.font.set({
    bold: false,
    italic: true,
    name: "Berlin Sans FB",
    color: "blue",
    size: 30
  });

  await context.sync();
});

insertTable(rowCount, columnCount, insertLocation, values)

指定した数の行と列を含むテーブルを挿入します。

insertTable(rowCount: number, columnCount: number, insertLocation: Word.InsertLocation.start | Word.InsertLocation.end | "Start" | "End", values?: string[][]): Word.Table;

パラメーター

rowCount

number

必須です。 表の行数。

columnCount

number

必須です。 表の列数。

insertLocation

start | end | "Start" | "End"

必須です。 値は 'Start' または 'End' である必要があります。

values

string[][]

省略可能な 2 次元配列。 対応する文字列が配列で指定されている場合、セルに設定されます。

戻り値

注釈

[ API セット: WordApi 1.3 ]

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/40-tables/table-cell-access.yaml

await Word.run(async (context) => {
  // Use a two-dimensional array to hold the initial table values.
  const data = [
    ["Tokyo", "Beijing", "Seattle"],
    ["Apple", "Orange", "Pineapple"]
  ];
  const table = context.document.body.insertTable(2, 3, "Start", data);
  table.styleBuiltIn = Word.BuiltInStyleName.gridTable5Dark_Accent2;
  table.styleFirstColumn = false;

  await context.sync();
});

insertText(text, insertLocation)

テキストを本文の指定された位置に挿入します。

insertText(text: string, insertLocation: Word.InsertLocation.replace | Word.InsertLocation.start | Word.InsertLocation.end | "Replace" | "Start" | "End"): Word.Range;

パラメーター

text

string

必須です。 挿入するテキスト。

insertLocation

replace | start | end | "Replace" | "Start" | "End"

必須です。 値は、'Replace'、'Start'、または 'End' である必要があります。

戻り値

注釈

[ API セット: WordApi 1.1 ]

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-body.yaml

// Inserts text at the beginning of this document.
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
  // Create a proxy object for the document body.
  const body = context.document.body;

  // Queue a command to insert text at the beginning of the current document.
  body.insertText('This is text inserted with body.insertText()', Word.InsertLocation.start);

  // Synchronize the document state by executing the queued commands, and return a promise to indicate task completion.
  await context.sync();

  console.log('Text added to the beginning of the document body.');
});

load(options)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

load(options?: Word.Interfaces.BodyLoadOptions): Word.Body;

パラメーター

options
Word.Interfaces.BodyLoadOptions

読み込むオブジェクトのプロパティのオプションを提供します。

戻り値

load(propertyNames)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

load(propertyNames?: string | string[]): Word.Body;

パラメーター

propertyNames

string | string[]

読み込むプロパティを指定するコンマ区切り文字列または文字列の配列。

戻り値

load(propertyNamesAndPaths)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

load(propertyNamesAndPaths?: {
            select?: string;
            expand?: string;
        }): Word.Body;

パラメーター

propertyNamesAndPaths

{ select?: string; expand?: string; }

propertyNamesAndPaths.select は、読み込むプロパティを指定するコンマ区切り文字列で propertyNamesAndPaths.expand 、読み込むナビゲーション プロパティを指定するコンマ区切りの文字列です。

戻り値

search(searchText, searchOptions)

body オブジェクトのスコープで、指定した SearchOptions を使用して検索を実行します。 検索結果は、範囲オブジェクトのコレクションです。

search(searchText: string, searchOptions?: Word.SearchOptions | {
            ignorePunct?: boolean;
            ignoreSpace?: boolean;
            matchCase?: boolean;
            matchPrefix?: boolean;
            matchSuffix?: boolean;
            matchWholeWord?: boolean;
            matchWildcards?: boolean;
        }): Word.RangeCollection;

パラメーター

searchText

string

必須です。 検索テキスト。 最大 255 文字を指定できます。

searchOptions

Word.SearchOptions | { ignorePunct?: boolean; ignoreSpace?: boolean; matchCase?: boolean; matchPrefix?: boolean; matchSuffix?: boolean; matchWholeWord?: boolean; matchWildcards?: boolean; }

オプション。 検索のオプション。

戻り値

注釈

[ API セット: WordApi 1.1 ]

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/25-paragraph/search.yaml

// Does a basic text search and highlights matches in the document.
await Word.run(async (context) => {
  const results = context.document.body.search("Online");
  results.load("length");

  await context.sync();

  // Let's traverse the search results and highlight matches.
  for (let i = 0; i < results.items.length; i++) {
    results.items[i].font.highlightColor = "yellow";
  }

  await context.sync();
});

...

// Does a wildcard search and highlights matches in the document.
await Word.run(async (context) => {
  // Construct a wildcard expression and set matchWildcards to true in order to use wildcards.
  const results = context.document.body.search("$*.[0-9][0-9]", { matchWildcards: true });
  results.load("length");

  await context.sync();

  // Let's traverse the search results and highlight matches.
  for (let i = 0; i < results.items.length; i++) {
    results.items[i].font.highlightColor = "red";
    results.items[i].font.color = "white";
  }

  await context.sync();
});

select(selectionMode)

本文を選択し、その本文に Word の UI を移動します。

select(selectionMode?: Word.SelectionMode): void;

パラメーター

selectionMode
Word.SelectionMode

オプション。 選択モードは、'Select'、'Start'、または 'End' である必要があります。 'Select' が既定値です。

戻り値

void

注釈

[ API セット: WordApi 1.1 ]

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-body.yaml

// Selects the entire body.
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
  // Create a proxy object for the document body.
  const body = context.document.body;

  // Queue a command to select the document body.
  // The Word UI will move to the selected document body.
  body.select();

  console.log("Selected the document body.");
});

select(selectionModeString)

本文を選択し、その本文に Word の UI を移動します。

select(selectionModeString?: "Select" | "Start" | "End"): void;

パラメーター

selectionModeString

"Select" | "Start" | "End"

オプション。 選択モードは、'Select'、'Start'、または 'End' である必要があります。 'Select' が既定値です。

戻り値

void

注釈

[ API セット: WordApi 1.1 ]

set(properties, options)

オブジェクトの複数のプロパティを同時に設定します。 適切なプロパティを持つプレーン オブジェクトまたは同じ型の別の API オブジェクトを渡すことができます。

set(properties: Interfaces.BodyUpdateData, options?: OfficeExtension.UpdateOptions): void;

パラメーター

properties
Word.Interfaces.BodyUpdateData

メソッドが呼び出されるオブジェクトのプロパティに等形的に構造化されたプロパティを持つ JavaScript オブジェクト。

options
OfficeExtension.UpdateOptions

properties オブジェクトが読み取り専用プロパティを設定しようとした場合にエラーを抑制するオプションを提供します。

戻り値

void

set(properties)

既存の読み込まれたオブジェクトに基づいて、オブジェクトに複数のプロパティを同時に設定します。

set(properties: Word.Body): void;

パラメーター

properties
Word.Body

戻り値

void

toJSON()

API オブジェクトが に渡されたときにより便利な出力を提供するために、JavaScript toJSON() メソッドを JSON.stringify()オーバーライドします。 (JSON.stringifyさらに、渡される オブジェクトの メソッドを呼び出toJSONします)。一方、元のWord。Body オブジェクトは API オブジェクトです。メソッドは、元のtoJSONオブジェクトから読み込まれた子プロパティの浅いコピーを含むプレーンな JavaScript オブジェクト (としてWord.Interfaces.BodyData型指定) を返します。

toJSON(): Word.Interfaces.BodyData;

戻り値

track()

ドキュメントの環境変更に基づいて自動的に調整する目的でオブジェクトを追跡します。 この呼び出しは、context.trackedObjects.add(thisObject)の短縮形です。 このオブジェクトを呼び出しで .sync 使用していて、".run" バッチのシーケンシャル実行の外部で使用していて、プロパティを設定するとき、またはオブジェクトのメソッドを呼び出すときに "InvalidObjectPath" エラーが発生する場合は、オブジェクトが最初に作成されたときに追跡対象のオブジェクト コレクションにオブジェクトを追加する必要があります。 このオブジェクトがコレクションの一部である場合は、親コレクションも追跡する必要があります。

track(): Word.Body;

戻り値

untrack()

前に追跡されていた場合、このオブジェクトに関連付けられているメモリを解放します。 この呼び出しは、context.trackedObjects.remove(thisObject)の短縮形です。 追跡対象オブジェクトが多いとホスト アプリケーションの動作が遅くなります。追加したオブジェクトが不要になったら、必ずそれを解放してください。 メモリ解放が有効になる前に を呼び出す context.sync() 必要があります。

untrack(): Word.Body;

戻り値

イベントの詳細

onCommentAdded

注意

この API は開発者向けにプレビューとして提供されており、寄せられたフィードバックにもとづいて変更される場合があります。 この API は運用環境で使用しないでください。

新しいコメントが追加されたときに発生します。

readonly onCommentAdded: OfficeExtension.EventHandlers<Word.CommentEventArgs>;

イベントの種類

注釈

[ API セット: WordApi BETA (プレビューのみ) ]

onCommentChanged

注意

この API は開発者向けにプレビューとして提供されており、寄せられたフィードバックにもとづいて変更される場合があります。 この API は運用環境で使用しないでください。

コメントまたはその応答が変更されたときに発生します。

readonly onCommentChanged: OfficeExtension.EventHandlers<Word.CommentEventArgs>;

イベントの種類

注釈

[ API セット: WordApi BETA (プレビューのみ) ]

onCommentDeleted

注意

この API は開発者向けにプレビューとして提供されており、寄せられたフィードバックにもとづいて変更される場合があります。 この API は運用環境で使用しないでください。

コメントが削除されたときに発生します。

readonly onCommentDeleted: OfficeExtension.EventHandlers<Word.CommentEventArgs>;

イベントの種類

注釈

[ API セット: WordApi BETA (プレビューのみ) ]

onCommentDeselected

注意

この API は開発者向けにプレビューとして提供されており、寄せられたフィードバックにもとづいて変更される場合があります。 この API は運用環境で使用しないでください。

コメントの選択が解除されたときに発生します。

readonly onCommentDeselected: OfficeExtension.EventHandlers<Word.CommentEventArgs>;

イベントの種類

注釈

[ API セット: WordApi BETA (プレビューのみ) ]

onCommentSelected

注意

この API は開発者向けにプレビューとして提供されており、寄せられたフィードバックにもとづいて変更される場合があります。 この API は運用環境で使用しないでください。

コメントが選択されたときに発生します。

readonly onCommentSelected: OfficeExtension.EventHandlers<Word.CommentEventArgs>;

イベントの種類

注釈

[ API セット: WordApi BETA (プレビューのみ) ]