Word.Paragraph class

選択部分、範囲、コンテンツ コントロール、または文書本文に含まれる 1 つの段落を表します。

Extends

注釈

[ API セット: WordApi 1.1 ]

プロパティ

alignment

段落の配置を指定します。 値には、"left"、"centered"、"right"、または "justified" を指定できます。

contentControls

段落内のコンテンツ コントロール オブジェクトのコレクションを取得します。

context

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

endnotes

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

fields

段落内のフィールドのコレクションを取得します。

firstLineIndent

最初の行またはぶら下げインデントの値をポイント単位で指定します。 最初の行のインデントを設定するのには正の値を使用し、ぶら下げインデントを設定するのには負の値を使用します。

font

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

footnotes

段落内の脚注のコレクションを取得します。

inlinePictures

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

isLastParagraph

段落がその親の本文内の最後の段落であることを示します。

isListItem

段落がリスト アイテムであるかどうかを確認します。

leftIndent

段落の左インデント値をポイント単位で指定します。

lineSpacing

指定した段落の行間をポイント単位で指定します。 Word UI では、この値が 12 で除算されます。

lineUnitAfter

段落の後のグリッド線の間隔を指定します。

lineUnitBefore

段落の前のグリッド線の間隔を指定します。

list

この段落が属するリストを取得します。 段落が ItemNotFound リストに含まれていない場合は、エラーをスローします。

listItem

段落の ListItem を取得します。 段落が ItemNotFound リストに含まれていない場合にエラーをスローします。

listItemOrNullObject

段落の ListItem を取得します。 段落がリストの一部でない場合、このメソッドは プロパティが に設定されたオブジェクトをisNullObjecttrue返します。 詳細については、「 *OrNullObject メソッドとプロパティ」を参照してください。

listOrNullObject

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

outlineLevel

段落のアウトライン レベルを指定します。

parentBody

段落の親の本文を取得します。

parentContentControl

段落を格納しているコンテンツ コントロールを取得します。 ItemNotFound親コンテンツ コントロールがない場合は、エラーをスローします。

parentContentControlOrNullObject

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

parentTable

段落を含むテーブルを取得します。 テーブルに ItemNotFound 含まれていない場合は、エラーをスローします。

parentTableCell

段落を含むテーブルのセルを取得します。 テーブル セルに ItemNotFound 含まれていない場合は、エラーをスローします。

parentTableCellOrNullObject

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

parentTableOrNullObject

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

rightIndent

段落の右インデント値をポイント単位で指定します。

spaceAfter

段落の後の間隔をポイント単位で指定します。

spaceBefore

段落の前の間隔をポイント単位で指定します。

style

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

styleBuiltIn

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

tableNestingLevel

段落のテーブルのレベルを取得します。 段落がテーブルにない場合は、0 を返します。

text

段落のテキストを取得します。

uniqueLocalId

現在のセッションの段落識別子を表す文字列を取得します。 ID は、中かっこのない標準の 8-4-4-4-12 GUID 形式であり、セッションと共同編集者によって異なります。

メソッド

attachToList(listId, level)

指定したレベルで段落を既存のリストに結合させます。 段落をリストに結合できない場合、または段落が既にリスト アイテムである場合は、失敗します。

clear()

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

delete()

文書から段落と、その段落の内容を削除します。

detachFromList()

段落がリスト アイテムである場合は、この段落をリストから移動します。

getAnnotations()

この Paragraph オブジェクトに設定された注釈を取得します。

getComments()

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

getContentControls(options)

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

getHtml()

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

getNext()

次の段落を取得します。 段落が ItemNotFound 最後の段落の場合は、エラーをスローします。

getNextOrNullObject()

次の段落を取得します。 段落が最後の段落の場合、このメソッドは プロパティが に設定されたオブジェクトをisNullObjecttrue返します。 詳細については、「 *OrNullObject メソッドとプロパティ」を参照してください。

getOoxml()

Paragraph オブジェクトの Office Open XML (OOXML) 表記を取得します。

getPrevious()

前の段落を取得します。 段落が最初の ItemNotFound 段落の場合は、エラーをスローします。

getPreviousOrNullObject()

前の段落を取得します。 段落が最初の段落の場合、このメソッドは プロパティが に設定されたオブジェクトをisNullObjecttrue返します。 詳細については、「 *OrNullObject メソッドとプロパティ」を参照してください。

getRange(rangeLocation)

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

getReviewedText(changeTrackingVersion)

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

getReviewedText(changeTrackingVersionString)

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

getText(options)

段落のテキストを返します。 これにより、数式、グラフィックス (画像、ビデオ、図面など)、さまざまなコンテンツをマークする特殊文字 (たとえば、コンテンツ コントロール、フィールド、コメント、脚注、エンドノーツなど) は除外されます。 既定では、非表示のテキストと、削除済みとしてマークされたテキストは除外されます。

getTextRanges(endingMarks, trimSpacing)

句読点やその他の終了記号を使用して、段落内のテキスト範囲を取得します。

getTrackedChanges()

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

insertAnnotations(annotations)

この Paragraph オブジェクトに注釈を挿入します。

insertBreak(breakType, insertLocation)

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

insertContentControl(contentControlType)

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

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)

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

select(selectionMode)

段落を選択して、その段落に Word の UI を移動します。

select(selectionModeString)

段落を選択して、その段落に Word の UI を移動します。

set(properties, options)

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

set(properties)

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

split(delimiters, trimDelimiters, trimSpacing)

区切り記号を使用して、段落を子の範囲に分割します。

startNewList()

この段落を含む新しいリストを開始します。 段落が既にリスト アイテムである場合は失敗します。

toJSON()

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

track()

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

untrack()

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

イベント

onCommentAdded

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

onCommentChanged

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

onCommentDeleted

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

onCommentDeselected

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

onCommentSelected

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

プロパティの詳細

alignment

段落の配置を指定します。 値には、"left"、"centered"、"right"、または "justified" を指定できます。

alignment: Word.Alignment | "Mixed" | "Unknown" | "Left" | "Centered" | "Right" | "Justified";

プロパティ値

Word.Alignment | "Mixed" | "Unknown" | "Left" | "Centered" | "Right" | "Justified"

注釈

[ API セット: WordApi 1.1 ]

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

await Word.run(async (context) => {
  // Center last paragraph alignment.
  context.document.body.paragraphs.getLast().alignment = "Centered";

  await context.sync();
});

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 ]

firstLineIndent

最初の行またはぶら下げインデントの値をポイント単位で指定します。 最初の行のインデントを設定するのには正の値を使用し、ぶら下げインデントを設定するのには負の値を使用します。

firstLineIndent: number;

プロパティ値

number

注釈

[ API セット: WordApi 1.1 ]

font

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

readonly font: Word.Font;

プロパティ値

注釈

[ API セット: WordApi 1.1 ]

footnotes

段落内の脚注のコレクションを取得します。

readonly footnotes: Word.NoteItemCollection;

プロパティ値

注釈

[ API セット: WordApi 1.5 ]

inlinePictures

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

readonly inlinePictures: Word.InlinePictureCollection;

プロパティ値

注釈

[ API セット: WordApi 1.1 ]

isLastParagraph

段落がその親の本文内の最後の段落であることを示します。

readonly isLastParagraph: boolean;

プロパティ値

boolean

注釈

[ API セット: WordApi 1.3 ]

isListItem

段落がリスト アイテムであるかどうかを確認します。

readonly isListItem: boolean;

プロパティ値

boolean

注釈

[ API セット: WordApi 1.3 ]

leftIndent

段落の左インデント値をポイント単位で指定します。

leftIndent: number;

プロパティ値

number

注釈

[ API セット: WordApi 1.1 ]

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

await Word.run(async (context) => {
  // Indent the first paragraph.
  context.document.body.paragraphs.getFirst().leftIndent = 75; //units = points

  return context.sync();
});

lineSpacing

指定した段落の行間をポイント単位で指定します。 Word UI では、この値が 12 で除算されます。

lineSpacing: number;

プロパティ値

number

注釈

[ API セット: WordApi 1.1 ]

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

await Word.run(async (context) => {
  // Adjust line spacing.
  context.document.body.paragraphs.getFirst().lineSpacing = 20;

  await context.sync();
});

lineUnitAfter

段落の後のグリッド線の間隔を指定します。

lineUnitAfter: number;

プロパティ値

number

注釈

[ API セット: WordApi 1.1 ]

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

await Word.run(async (context) => {
  // Set the space (in line units) after the first paragraph.
  context.document.body.paragraphs.getFirst().lineUnitAfter = 1;

  await context.sync();
});

lineUnitBefore

段落の前のグリッド線の間隔を指定します。

lineUnitBefore: number;

プロパティ値

number

注釈

[ API セット: WordApi 1.1 ]

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

await Word.run(async (context) => {
  // Set the space (in line units) before the first paragraph.
  context.document.body.paragraphs.getFirst().lineUnitBefore = 1;

  await context.sync();
});

list

この段落が属するリストを取得します。 段落が ItemNotFound リストに含まれていない場合は、エラーをスローします。

readonly list: Word.List;

プロパティ値

注釈

[ API セット: WordApi 1.3 ]

listItem

段落の ListItem を取得します。 段落が ItemNotFound リストに含まれていない場合にエラーをスローします。

readonly listItem: Word.ListItem;

プロパティ値

注釈

[ API セット: WordApi 1.3 ]

listItemOrNullObject

段落の ListItem を取得します。 段落がリストの一部でない場合、このメソッドは プロパティが に設定されたオブジェクトをisNullObjecttrue返します。 詳細については、「 *OrNullObject メソッドとプロパティ」を参照してください。

readonly listItemOrNullObject: Word.ListItem;

プロパティ値

注釈

[ API セット: WordApi 1.3 ]

listOrNullObject

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

readonly listOrNullObject: Word.List;

プロパティ値

注釈

[ API セット: WordApi 1.3 ]

outlineLevel

段落のアウトライン レベルを指定します。

outlineLevel: number;

プロパティ値

number

注釈

[ API セット: WordApi 1.1 ]

parentBody

段落の親の本文を取得します。

readonly parentBody: 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 ]

parentTable

段落を含むテーブルを取得します。 テーブルに ItemNotFound 含まれていない場合は、エラーをスローします。

readonly parentTable: Word.Table;

プロパティ値

注釈

[ API セット: WordApi 1.3 ]

parentTableCell

段落を含むテーブルのセルを取得します。 テーブル セルに ItemNotFound 含まれていない場合は、エラーをスローします。

readonly parentTableCell: Word.TableCell;

プロパティ値

注釈

[ API セット: WordApi 1.3 ]

parentTableCellOrNullObject

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

readonly parentTableCellOrNullObject: Word.TableCell;

プロパティ値

注釈

[ API セット: WordApi 1.3 ]

parentTableOrNullObject

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

readonly parentTableOrNullObject: Word.Table;

プロパティ値

注釈

[ API セット: WordApi 1.3 ]

rightIndent

段落の右インデント値をポイント単位で指定します。

rightIndent: number;

プロパティ値

number

注釈

[ API セット: WordApi 1.1 ]

spaceAfter

段落の後の間隔をポイント単位で指定します。

spaceAfter: number;

プロパティ値

number

注釈

[ API セット: WordApi 1.1 ]

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

await Word.run(async (context) => {
  // Set the space (in points) after the first paragraph.
  context.document.body.paragraphs.getFirst().spaceAfter = 20;

  await context.sync();
});

spaceBefore

段落の前の間隔をポイント単位で指定します。

spaceBefore: number;

プロパティ値

number

注釈

[ API セット: WordApi 1.1 ]

style

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

style: string;

プロパティ値

string

注釈

[ API セット: WordApi 1.1 ]

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

// Applies the specified style to a paragraph.
await Word.run(async (context) => {
  const styleName = $("#style-name-to-use").val() as string;
  if (styleName == "") {
    console.warn("Enter a style name to apply.");
    return;
  }

  const style = context.document.getStyles().getByNameOrNullObject(styleName);
  style.load();
  await context.sync();

  if (style.isNullObject) {
    console.warn(`There's no existing style with the name '${styleName}'.`);
  } else if (style.type != Word.StyleType.paragraph) {
    console.log(`The '${styleName}' style isn't a paragraph style.`);
  } else {
    const body = context.document.body;
    body.clear();
    body.insertParagraph(
      "Video provides a powerful way to help you prove your point. When you click Online Video, you can paste in the embed code for the video you want to add. You can also type a keyword to search online for the video that best fits your document.",
      "Start"
    );
    const paragraph = body.paragraphs.getFirst();
    paragraph.style = style.nameLocal;
    console.log(`'${styleName}' style applied to first paragraph.`);
  }
});

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 ]

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/90-scenarios/doc-assembly.yaml

await Word.run(async (context) => {
    const paragraph = context.document.body.insertParagraph("Timeline", "End");
    paragraph.styleBuiltIn = "Heading2";
    const paragraph2 = context.document.body.insertParagraph("The Services shall commence on July 31, 2015, and shall continue through July 29, 2015.", "End");
    paragraph2.styleBuiltIn = "Normal";
    const paragraph3 = context.document.body.insertParagraph("Project Costs by Phase", "End");
    paragraph3.styleBuiltIn = "Heading2";
    // Note a content control with the title of "ProjectCosts" is added. Content will be replaced later.
    const paragraph4 = context.document.body.insertParagraph("<Add Project Costs Here>", "End");
    paragraph4.styleBuiltIn = "Normal";
    paragraph4.font.highlightColor = "#FFFF00";
    const contentControl = paragraph4.insertContentControl();
    contentControl.title = "ProjectCosts";
    const paragraph5 = context.document.body.insertParagraph("Project Team", "End");
    paragraph5.styleBuiltIn = "Heading2";
    paragraph5.font.highlightColor = "#FFFFFF";
    const paragraph6 = context.document.body.insertParagraph("Terms of Work", "End");
    paragraph6.styleBuiltIn = "Heading1";
    const paragraph7 = context.document.body.insertParagraph("Contractor shall provide the Services and Deliverable(s) as follows:", "End");
    paragraph7.styleBuiltIn = "Normal";
    const paragraph8 = context.document.body.insertParagraph("Out-of-Pocket Expenses / Invoice Procedures", "End");
    paragraph8.styleBuiltIn = "Heading2";
    const paragraph9 = context.document.body.insertParagraph("Client will be invoiced monthly for the consulting services and T&L expenses. Standard Contractor invoicing is assumed to be acceptable. Invoices are due upon receipt. client will be invoiced all costs associated with out-of-pocket expenses (including, without limitation, costs and expenses associated with meals, lodging, local transportation and any other applicable business expenses) listed on the invoice as a separate line item. Reimbursement for out-of-pocket expenses in connection with performance of this SOW, when authorized and up to the limits set forth in this SOW, shall be in accordance with Client's then-current published policies governing travel and associated business expenses, which information shall be provided by the Client Project Manager.", "End");
    paragraph9.styleBuiltIn = "Normal";
    // Insert a page break at the end of the document.
    context.document.body.insertBreak("Page", "End");

    await context.sync();
});

tableNestingLevel

段落のテーブルのレベルを取得します。 段落がテーブルにない場合は、0 を返します。

readonly tableNestingLevel: number;

プロパティ値

number

注釈

[ API セット: WordApi 1.3 ]

text

段落のテキストを取得します。

readonly text: string;

プロパティ値

string

注釈

[ API セット: WordApi 1.1 ]

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

await Word.run(async (context) => {
  // The collection of paragraphs of the current selection returns the full paragraphs contained in it.
  const paragraph = context.document.getSelection().paragraphs.getFirst();
  paragraph.load("text");

  await context.sync();
  console.log(paragraph.text);
});

uniqueLocalId

現在のセッションの段落識別子を表す文字列を取得します。 ID は、中かっこのない標準の 8-4-4-4-12 GUID 形式であり、セッションと共同編集者によって異なります。

readonly uniqueLocalId: string;

プロパティ値

string

注釈

[ API セット: WordApi 1.6 ]

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

// Registers event handlers.
await Word.run(async (context) => {
  eventContexts[0] = context.document.onParagraphAdded.add(paragraphChanged);
  eventContexts[1] = context.document.onParagraphChanged.add(paragraphChanged);

  eventContexts[2] = context.document.onAnnotationClicked.add(onClickedHandler);
  eventContexts[3] = context.document.onAnnotationHovered.add(onHoveredHandler);
  eventContexts[4] = context.document.onAnnotationInserted.add(onInsertedHandler);
  eventContexts[5] = context.document.onAnnotationRemoved.add(onRemovedHandler);

  await context.sync();

  console.log("Event handlers registered.");
});

...

async function paragraphChanged(args: Word.ParagraphChangedEventArgs) {
  await Word.run(async (context) => {
    const results = [];
    for (let id of args.uniqueLocalIds) {
      let para = context.document.getParagraphByUniqueLocalId(id);
      para.load("uniqueLocalId");

      results.push({ para: para, text: para.getText() });
    }

    await context.sync();

    for (let result of results) {
      console.log(`${args.type}: ${result.para.uniqueLocalId} - ${result.text.value}`);
    }
  });
}

メソッドの詳細

attachToList(listId, level)

指定したレベルで段落を既存のリストに結合させます。 段落をリストに結合できない場合、または段落が既にリスト アイテムである場合は、失敗します。

attachToList(listId: number, level: number): Word.List;

パラメーター

listId

number

必須です。 既存のリストの ID。

level

number

必須です。 一覧のレベル。

戻り値

注釈

[ API セット: WordApi 1.3 ]

clear()

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

clear(): void;

戻り値

void

注釈

[ API セット: WordApi 1.1 ]

// Run a batch operation against the Word object model.
await Word.run(async (context) => {

    // Create a proxy object for the paragraphs collection.
    const paragraphs = context.document.body.paragraphs;

    // Queue a command to load the style property for all of the paragraphs.
    paragraphs.load('style');

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

    // Queue a command to clear the contents of the first paragraph.
    paragraphs.items[0].clear();

    // Synchronize the document state by executing the queued commands,
    // and return a promise to indicate task completion.
    await context.sync();
    console.log('Cleared the contents of the first paragraph.');
});

delete()

文書から段落と、その段落の内容を削除します。

delete(): void;

戻り値

void

注釈

[ API セット: WordApi 1.1 ]

// Run a batch operation against the Word object model.
await Word.run(async (context) => {

    // Create a proxy object for the paragraphs collection.
    const paragraphs = context.document.body.paragraphs;

    // Queue a command to load the text property for all of the paragraphs.
    paragraphs.load('text');

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

    // Queue a command to delete the first paragraph.
    paragraphs.items[0].delete();

    // Synchronize the document state by executing the queued commands,
    // and return a promise to indicate task completion.
    await context.sync();
    console.log('Deleted the first paragraph.');
});

detachFromList()

段落がリスト アイテムである場合は、この段落をリストから移動します。

detachFromList(): void;

戻り値

void

注釈

[ API セット: WordApi 1.3 ]

getAnnotations()

この Paragraph オブジェクトに設定された注釈を取得します。

getAnnotations(): Word.AnnotationCollection;

戻り値

注釈

[ API セット: WordApi 1.7 ]

getComments()

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

getComments(): Word.CommentCollection;

戻り値

注釈

[ API セット: WordApi 1.4 ]

getContentControls(options)

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

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

パラメーター

options
Word.ContentControlOptions

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

戻り値

注釈

[ API セット: WordApi 1.5 ]

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

getHtml()

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

getHtml(): OfficeExtension.ClientResult<string>;

戻り値

注釈

[ API セット: WordApi 1.1 ]

// Run a batch operation against the Word object model.
await Word.run(async (context) => {

    // Create a proxy object for the paragraphs collection.
    const paragraphs = context.document.body.paragraphs;

    // Queue a command to load the style property for all of the paragraphs.
    paragraphs.load('style');

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

    // Queue a set of commands to get the HTML of the first paragraph.
    const html = paragraphs.items[0].getHtml();

    // Synchronize the document state by executing the queued commands,
    // and return a promise to indicate task completion.
    await context.sync();
    console.log('Paragraph HTML: ' + html.value);
});

getNext()

次の段落を取得します。 段落が ItemNotFound 最後の段落の場合は、エラーをスローします。

getNext(): Word.Paragraph;

戻り値

注釈

[ API セット: WordApi 1.3 ]

getNextOrNullObject()

次の段落を取得します。 段落が最後の段落の場合、このメソッドは プロパティが に設定されたオブジェクトをisNullObjecttrue返します。 詳細については、「 *OrNullObject メソッドとプロパティ」を参照してください。

getNextOrNullObject(): Word.Paragraph;

戻り値

注釈

[ API セット: WordApi 1.3 ]

getOoxml()

Paragraph オブジェクトの Office Open XML (OOXML) 表記を取得します。

getOoxml(): OfficeExtension.ClientResult<string>;

戻り値

注釈

[ API セット: WordApi 1.1 ]

// Run a batch operation against the Word object model.
await Word.run(async (context) => {

    // Create a proxy object for the paragraphs collection.
    const paragraphs = context.document.body.paragraphs;

    // Queue a command to load the style property for the top 2 paragraphs.
    paragraphs.load({select: 'style', top: 2} );

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

    // Queue a set of commands to get the OOXML of the first paragraph.
    const ooxml = paragraphs.items[0].getOoxml();

    // Synchronize the document state by executing the queued commands,
    // and return a promise to indicate task completion.
    await context.sync();
    console.log('Paragraph OOXML: ' + ooxml.value);
});

getPrevious()

前の段落を取得します。 段落が最初の ItemNotFound 段落の場合は、エラーをスローします。

getPrevious(): Word.Paragraph;

戻り値

注釈

[ API セット: WordApi 1.3 ]

getPreviousOrNullObject()

前の段落を取得します。 段落が最初の段落の場合、このメソッドは プロパティが に設定されたオブジェクトをisNullObjecttrue返します。 詳細については、「 *OrNullObject メソッドとプロパティ」を参照してください。

getPreviousOrNullObject(): Word.Paragraph;

戻り値

注釈

[ API セット: WordApi 1.3 ]

// Run a batch operation against the Word object model.
await Word.run(async (context) => {

    // Create a proxy object for the paragraphs collection.
    const paragraphs = context.document.body.paragraphs;

    // Queue a command to load the text property for all of the paragraphs.
    paragraphs.load('text');

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

    // Queue commands to create a proxy object for the next-to-last paragraph.
    const indexOfLastParagraph = paragraphs.items.length - 1;
    const precedingParagraph = paragraphs.items[indexOfLastParagraph].getPreviousOrNullObject();

    // Queue a command to load the text of the preceding paragraph.
    precedingParagraph.load('text');

    // Synchronize the document state by executing the queued commands,
    // and return a promise to indicate task completion.
    await context.sync();
    if (precedingParagraph.isNullObject) {
        console.log('There are no paragraphs before the current one.');
    } else {
        console.log('The preceding paragraph is: ' + precedingParagraph.text);
    }
});

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 ]

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

await Word.run(async (context) => {
  // Get the complete sentence (as range) associated with the insertion point.
  const sentences = context.document
    .getSelection()
    .getTextRanges(["."] /* Using the "." as delimiter */, false /*means without trimming spaces*/);
  sentences.load("$none");
  await context.sync();

  // Expand the range to the end of the paragraph to get all the complete sentences.
  const sentencesToTheEndOfParagraph = sentences.items[0]
    .getRange()
    .expandTo(
      context.document
        .getSelection()
        .paragraphs.getFirst()
        .getRange(Word.RangeLocation.end)
    )
    .getTextRanges(["."], false /* Don't trim spaces*/);
  sentencesToTheEndOfParagraph.load("text");
  await context.sync();

  for (let i = 0; i < sentencesToTheEndOfParagraph.items.length; i++) {
    console.log(sentencesToTheEndOfParagraph.items[i].text);
  }
});

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 ]

getText(options)

段落のテキストを返します。 これにより、数式、グラフィックス (画像、ビデオ、図面など)、さまざまなコンテンツをマークする特殊文字 (たとえば、コンテンツ コントロール、フィールド、コメント、脚注、エンドノーツなど) は除外されます。 既定では、非表示のテキストと、削除済みとしてマークされたテキストは除外されます。

getText(options?: Word.GetTextOptions | {
            IncludeHiddenText?: boolean;
            IncludeTextMarkedAsDeleted?: boolean;
        }): OfficeExtension.ClientResult<string>;

パラメーター

options

Word.GetTextOptions | { IncludeHiddenText?: boolean; IncludeTextMarkedAsDeleted?: boolean; }

オプション。 最終的な結果に非表示のテキストと、削除済みとしてマークされたテキストを含めるかどうかを定義するオプション。

戻り値

注釈

[ API セット: WordApi 1.7 ]

getTextRanges(endingMarks, trimSpacing)

句読点やその他の終了記号を使用して、段落内のテキスト範囲を取得します。

getTextRanges(endingMarks: string[], trimSpacing?: boolean): Word.RangeCollection;

パラメーター

endingMarks

string[]

必須です。 句読点や他の終了記号を文字列の配列として指定します。

trimSpacing

boolean

オプション。 範囲コレクションで返される範囲の先頭と末尾から間隔文字 (スペース、タブ、列区切り、段落の終了記号) をトリミングするかどうかを示します。 既定値は false で、範囲の先頭と末尾の間隔文字が範囲コレクションに含まれることを示します。

戻り値

注釈

[ API セット: WordApi 1.3 ]

getTrackedChanges()

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

getTrackedChanges(): Word.TrackedChangeCollection;

戻り値

注釈

[ API セット: WordApi 1.6 ]

insertAnnotations(annotations)

この Paragraph オブジェクトに注釈を挿入します。

insertAnnotations(annotations: Word.AnnotationSet): OfficeExtension.ClientResult<string[]>;

パラメーター

annotations
Word.AnnotationSet

設定する注釈。

戻り値

挿入された注釈識別子の配列。

注釈

[ API セット: WordApi 1.7 ]

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

// Adds annotations to the selected paragraph.
await Word.run(async (context) => {
  const paragraph = context.document.getSelection().paragraphs.getFirst();
  const critique1 = {
    colorScheme: Word.CritiqueColorScheme.red,
    start: 1,
    length: 3
  };
  const critique2 = {
    colorScheme: Word.CritiqueColorScheme.green,
    start: 6,
    length: 1
  };
  const critique3 = {
    colorScheme: Word.CritiqueColorScheme.blue,
    start: 10,
    length: 3
  };
  const critique4 = {
    colorScheme: Word.CritiqueColorScheme.lavender,
    start: 14,
    length: 3
  };
  const critique5 = {
    colorScheme: Word.CritiqueColorScheme.berry,
    start: 18,
    length: 10
  };
  const annotationSet: Word.AnnotationSet = {
    critiques: [critique1, critique2, critique3, critique4, critique5]
  };

  const annotationIds = paragraph.insertAnnotations(annotationSet);

  await context.sync();

  console.log("Annotations inserted:", annotationIds.value);
});

insertBreak(breakType, insertLocation)

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

insertBreak(breakType: Word.BreakType | "Page" | "Next" | "SectionNext" | "SectionContinuous" | "SectionEven" | "SectionOdd" | "Line", insertLocation: Word.InsertLocation.before | Word.InsertLocation.after | "Before" | "After"): void;

パラメーター

breakType

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

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

insertLocation

before | after | "Before" | "After"

必須です。 値は 'Before' または 'After' である必要があります。

戻り値

void

注釈

[ API セット: WordApi 1.1 ]

// Run a batch operation against the Word object model.
await Word.run(async (context) => {

    // Create a proxy object for the paragraphs collection.
    const paragraphs = context.document.body.paragraphs;

    // Queue a command to load the style property for the top 2 paragraphs.
    // We never perform an empty load. We always must request a property.
    paragraphs.load({select: 'style', top: 2} );

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

    // Queue a command to get the first paragraph.
    const paragraph = paragraphs.items[0];

    // Queue a command to insert a page break after the first paragraph.
    paragraph.insertBreak(Word.BreakType.page, Word.InsertLocation.after);

    // Synchronize the document state by executing the queued commands,
    // and return a promise to indicate task completion.
    await context.sync();
    console.log('Inserted a page break after the paragraph.');
});
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/25-paragraph/insert-line-and-page-breaks.yaml

Word.run(async (context) => {
  context.document.body.paragraphs.getFirst().insertBreak(Word.BreakType.line, "After");

  await context.sync();
  console.log("success");
});

insertContentControl(contentControlType)

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

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 でサポートが追加されました。

// Run a batch operation against the Word object model.
await Word.run(async (context) => {

    // Create a proxy object for the paragraphs collection.
    const paragraphs = context.document.body.paragraphs;

    // Queue a command to load the style property for the top 2 paragraphs.
    // We never perform an empty load. We always must request a property.
    paragraphs.load({select: 'style', top: 2} );

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

    // Queue a command to get the first paragraph.
    const paragraph = paragraphs.items[0];

    // Queue a command to wrap the first paragraph in a rich text content control.
    paragraph.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 first paragraph 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 コントロールが含まれている場合 (フォーム フィールドの可能性があります)、挿入はサポートされません。 このようなフォーム フィールドを、シナリオに適したコンテンツ コントロールまたはその他のオプションに置き換えることを検討してください。

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 ]

// Run a batch operation against the Word object model.
await Word.run(async (context) => {

    // Create a proxy object for the paragraphs collection.
    const paragraphs = context.document.body.paragraphs;

    // Queue a command to load the style property for the top 2 paragraphs.
    // We never perform an empty load. We always must request a property.
    paragraphs.load({select: 'style', top: 2} );

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

    // Queue a command to get the first paragraph.
    const paragraph = paragraphs.items[0];

    // Queue a command to insert HTML content at the end of the first paragraph.
    paragraph.insertHtml('<strong>Inserted HTML.</strong>', Word.InsertLocation.end);

    // Synchronize the document state by executing the queued commands,
    // and return a promise to indicate task completion.
    await context.sync();
    console.log('Inserted HTML content at the end of the first paragraph.');
});

insertInlinePictureFromBase64(base64EncodedImage, insertLocation)

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

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

パラメーター

base64EncodedImage

string

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

insertLocation

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

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

戻り値

注釈

[ API セット: WordApi 1.1 ]

// Run a batch operation against the Word object model.
await Word.run(async (context) => {

    // Create a proxy object for the paragraphs collection.
    const paragraphs = context.document.body.paragraphs;

    // Queue a command to load the style property for all of the paragraphs.
    paragraphs.load('style');

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

    // Queue a command to get the first paragraph.
    const paragraph = paragraphs.items[0];

    const b64encodedImg = "iVBORw0KGgoAAAANSUhEUgAAAB4AAAANCAIAAAAxEEnAAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACFSURBVDhPtY1BEoQwDMP6/0+XgIMTBAeYoTqso9Rkx1zG+tNj1H94jgGzeNSjteO5vtQQuG2seO0av8LzGbe3anzRoJ4ybm/VeKEerAEbAUpW4aWQCmrGFWykRzGBCnYy2ha3oAIq2MloW9yCCqhgJ6NtcQsqoIKdjLbFLaiACnYyf2fODbrjZcXfr2F4AAAAAElFTkSuQmCC";

    // Queue a command to insert a base64 encoded image at the beginning of the first paragraph.
    paragraph.insertInlinePictureFromBase64(b64encodedImg, 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 an image to the first paragraph.');
});

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 ]

insertParagraph(paragraphText, insertLocation)

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

insertParagraph(paragraphText: string, insertLocation: Word.InsertLocation.before | Word.InsertLocation.after | "Before" | "After"): Word.Paragraph;

パラメーター

paragraphText

string

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

insertLocation

before | after | "Before" | "After"

必須です。 値は 'Before' または 'After' である必要があります。

戻り値

注釈

[ API セット: WordApi 1.1 ]

insertTable(rowCount, columnCount, insertLocation, values)

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

insertTable(rowCount: number, columnCount: number, insertLocation: Word.InsertLocation.before | Word.InsertLocation.after | "Before" | "After", values?: string[][]): Word.Table;

パラメーター

rowCount

number

必須です。 表の行数。

columnCount

number

必須です。 表の列数。

insertLocation

before | after | "Before" | "After"

必須です。 値は 'Before' または 'After' である必要があります。

values

string[][]

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

戻り値

注釈

[ API セット: WordApi 1.3 ]

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/25-paragraph/insert-in-different-locations.yaml

await Word.run(async (context) => {
  // Replace the last paragraph.
  const range = context.document.body.paragraphs.getLast().insertText("Just replaced the last paragraph!", "Replace");
  range.font.highlightColor = "black";
  range.font.color = "white";

  await context.sync();
});

load(options)

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

load(options?: Word.Interfaces.ParagraphLoadOptions): Word.Paragraph;

パラメーター

options
Word.Interfaces.ParagraphLoadOptions

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

戻り値

load(propertyNames)

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

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

パラメーター

propertyNames

string | string[]

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

戻り値

load(propertyNamesAndPaths)

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

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

パラメーター

propertyNamesAndPaths

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

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

戻り値

search(searchText, searchOptions)

指定した 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

必須です。 検索テキスト。

searchOptions

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

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

戻り値

注釈

[ API セット: WordApi 1.1 ]

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/35-ranges/scroll-to-range.yaml

await Word.run(async (context) => {
  // If select is called with no parameters, it selects the object.
  context.document.body.paragraphs.getLast().select();

  await context.sync();
});

...

await Word.run(async (context) => {
  // Select can be at the start or end of a range; this by definition moves the insertion point without selecting the range.
  context.document.body.paragraphs.getLast().select(Word.SelectionMode.end);

  await context.sync();
});

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.ParagraphUpdateData, options?: OfficeExtension.UpdateOptions): void;

パラメーター

properties
Word.Interfaces.ParagraphUpdateData

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

options
OfficeExtension.UpdateOptions

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

戻り値

void

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/90-scenarios/multiple-property-set.yaml

await Word.run(async (context) => {
  const paragraph = context.document.body.paragraphs.getFirst();
  paragraph.set({
    leftIndent: 30,
    font: {
      bold: true,
      color: "red"
    }
  });

  await context.sync();
});

...

await Word.run(async (context) => {
  const firstParagraph = context.document.body.paragraphs.getFirst();
  const secondParagraph = firstParagraph.getNext();
  firstParagraph.load("text, font/color, font/bold, leftIndent");

  await context.sync();

  secondParagraph.set(firstParagraph);

  await context.sync();
});

set(properties)

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

set(properties: Word.Paragraph): void;

パラメーター

properties
Word.Paragraph

戻り値

void

split(delimiters, trimDelimiters, trimSpacing)

区切り記号を使用して、段落を子の範囲に分割します。

split(delimiters: string[], trimDelimiters?: boolean, trimSpacing?: boolean): Word.RangeCollection;

パラメーター

delimiters

string[]

必須です。 文字列の配列としての区切り記号。

trimDelimiters

boolean

オプション。 範囲コレクション内の範囲から区切り記号をトリミングするかどうかを示します。 既定値は false で、範囲コレクションで返される範囲に区切り記号が含まれていることを示します。

trimSpacing

boolean

オプション。 範囲コレクションで返される範囲の先頭と末尾から間隔文字 (スペース、タブ、列区切り、段落の終了記号) をトリミングするかどうかを示します。 既定値は false で、範囲の先頭と末尾の間隔文字が範囲コレクションに含まれることを示します。

戻り値

注釈

[ API セット: WordApi 1.3 ]

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/split-words-of-first-paragraph.yaml

await Word.run(async (context) => {
  const paragraph = context.document.body.paragraphs.getFirst();
  const words = paragraph.split([" "], true /* trimDelimiters*/, true /* trimSpaces */);
  words.load("text");

  await context.sync();

  for (let i = 0; i < words.items.length; i++) {
    if (i >= 1) {
      words.items[i - 1].font.highlightColor = "#FFFFFF";
    }
    words.items[i].font.highlightColor = "#FFFF00";

    await context.sync();
    await pause(200);
  }
});

startNewList()

この段落を含む新しいリストを開始します。 段落が既にリスト アイテムである場合は失敗します。

startNewList(): Word.List;

戻り値

注釈

[ API セット: WordApi 1.3 ]

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/20-lists/insert-list.yaml

// This example starts a new list with the second paragraph.
await Word.run(async (context) => {
  const paragraphs = context.document.body.paragraphs;
  paragraphs.load("$none");

  await context.sync();

  // Start new list using the second paragraph.
  const list = paragraphs.items[1].startNewList();
  list.load("$none");

  await context.sync();

  // To add new items to the list, use Start or End on the insertLocation parameter.
  list.insertParagraph("New list item at the start of the list", "Start");
  const paragraph = list.insertParagraph("New list item at the end of the list (set to list level 5)", "End");

  // Set up list level for the list item.
  paragraph.listItem.level = 4;

  // To add paragraphs outside the list, use Before or After.
  list.insertParagraph("New paragraph goes after (not part of the list)", "After");

  await context.sync();
});

toJSON()

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

toJSON(): Word.Interfaces.ParagraphData;

戻り値

track()

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

track(): Word.Paragraph;

戻り値

untrack()

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

untrack(): Word.Paragraph;

戻り値

イベントの詳細

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 (プレビューのみ) ]