Word.Paragraph class

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

Extends

注釈

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: Word.Paragraph = context.document.getSelection().paragraphs.getFirst();
  paragraph.load("text");

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

プロパティ

alignment

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

borders

段落のすべての境界線を表す BorderUniversalCollection オブジェクトを返します。

contentControls

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

context

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

endnotes

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

fields

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

firstLineIndent

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

font

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

footnotes

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

inlinePictures

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

isLastParagraph

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

isListItem

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

leftIndent

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

lineSpacing

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

lineUnitAfter

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

lineUnitBefore

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

list

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

listItem

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

listItemOrNullObject

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

listOrNullObject

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

outlineLevel

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

parentBody

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

parentContentControl

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

parentContentControlOrNullObject

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

parentTable

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

parentTableCell

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

parentTableCellOrNullObject

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

parentTableOrNullObject

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

rightIndent

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

shading

段落の網かけ形式を参照する ShadingUniversal オブジェクトを返します。

shapes

インライン図形とフローティング図形の両方を含む、段落に固定されている Shape オブジェクトのコレクションを取得します。 現時点では、テキスト ボックス、幾何学的図形、グループ、画像、キャンバスの図形のみがサポートされています。

spaceAfter

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

spaceBefore

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

style

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

styleBuiltIn

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

tableNestingLevel

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

text

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

uniqueLocalId

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

メソッド

attachToList(listId, level)

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

clear()

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

closeUp()

段落の前のスペースを削除します。

delete()

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

detachFromList()

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

getAnnotations()

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

getComments()

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

getContentControls(options)

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

getHtml()

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

getNext()

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

getNextOrNullObject()

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

getOoxml()

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

getPrevious()

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

getPreviousOrNullObject()

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

getRange(rangeLocation)

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

getReviewedText(changeTrackingVersion)

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

getReviewedText(changeTrackingVersion)

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

getText(options)

段落のテキストを返します。 これには、数式、グラフィックス (画像、ビデオ、描画など)、およびさまざまなコンテンツをマークする特殊文字 (コンテンツ コントロール、フィールド、コメント、脚注、文末脚注など) は含まれません。 既定では、隠しテキストと削除済みとマークされたテキストは除外されます。

getTextRanges(endingMarks, trimSpacing)

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

getTrackedChanges()

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

indent()

段落を 1 レベルインデントします。

indentCharacterWidth(count)

指定した文字数だけ段落をインデントします。

indentFirstLineCharacterWidth(count)

段落の最初の行を指定された文字数だけインデントします。

insertAnnotations(annotations)

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

insertBreak(breakType, insertLocation)

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

insertCanvas(insertShapeOptions)

アンカーを段落の先頭に配置して、テキストの前にフローティング キャンバスを挿入します。

insertContentControl(contentControlType)

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

insertFileFromBase64(base64File, insertLocation)

指定した位置にある段落にドキュメントを挿入します。

insertGeometricShape(geometricShapeType, insertShapeOptions)

テキストの前に幾何学図形を挿入し、アンカーを段落の先頭に配置します。

insertGeometricShape(geometricShapeType, insertShapeOptions)

テキストの前に幾何学図形を挿入し、アンカーを段落の先頭に配置します。

insertHtml(html, insertLocation)

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

insertInlinePictureFromBase64(base64EncodedImage, insertLocation)

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

insertOoxml(ooxml, insertLocation)

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

insertParagraph(paragraphText, insertLocation)

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

insertPictureFromBase64(base64EncodedImage, insertShapeOptions)

アンカーを段落の先頭に配置して、テキストの前に浮動画像を挿入します。

insertTable(rowCount, columnCount, insertLocation, values)

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

insertText(text, insertLocation)

段落の指定した位置に、テキストを挿入します。

insertTextBox(text, insertShapeOptions)

テキストの前にフローティング テキスト ボックスを挿入し、アンカーを段落の先頭に配置します。

joinList()

この段落の上または下に最も近いリストを持つリスト段落を結合します。

load(options)

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

load(propertyNames)

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

load(propertyNamesAndPaths)

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

next(count)

次の段落を示す Paragraph オブジェクトを返します。

openOrCloseUp()

段落の前の間隔を切り替えます。

openUp()

段落前の間隔を 12 ポイントに設定します。

outdent()

段落のインデントを 1 レベル削除します。

outlineDemote()

次の見出しレベル スタイル (見出し 1 から見出し 8) を段落に適用します。

outlineDemoteToBody()

標準スタイルを適用して、段落を本文テキストに降格します。

outlinePromote()

前の見出しレベル スタイル (見出し 1 から見出し 8) を段落に適用します。

previous(count)

前の段落を Paragraph オブジェクトとして返します。

reset()

手動で指定した段落書式 (スタイルを使わずに設定した書式) を削除します。

resetAdvanceTo()

カスタム リスト レベルを使用する段落を元のレベル設定にリセットします。

search(searchText, searchOptions)

Paragraph オブジェクトのスコープに対して、指定された検索オプションを使用して検索を実行します。 検索結果は、 Range オブジェクトのコレクションです。

select(selectionMode)

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

select(selectionMode)

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

selectNumber()

箇条書きの段落番号または行頭文字を選択します。

separateList()

1 つのリストを 2 つのリストに分割します。 段落番号の場合、新しいリストは開始番号 (通常 1) から番号付けが再開されます。

set(properties, options)

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

set(properties)

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

space1()

段落をシングル スペースに設定します。

space1Pt5()

段落を 1.5 行間隔に設定します。

space2()

段落をダブル スペースに設定します。

split(delimiters, trimDelimiters, trimSpacing)

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

startNewList()

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

tabHangingIndent(count)

指定されたタブ位置にぶら下げインデントを設定します。

tabIndent(count)

段落の左インデントを、指定したタブ位置の数に設定します。

toJSON()

API オブジェクトが JSON.stringify() に渡されるときに、より有用な出力を提供するために、JavaScript toJSON() メソッドをオーバーライドします。 (次に、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

段落の配置を指定します。 値には、 leftcenteredright、または 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();
});

borders

段落のすべての境界線を表す BorderUniversalCollection オブジェクトを返します。

readonly borders: Word.BorderUniversalCollection;

プロパティ値

注釈

API セット: WordApiDesktop 1.3

contentControls

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

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

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

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

readonly listItemOrNullObject: Word.ListItem;

プロパティ値

注釈

API セット: WordApi 1.3

listOrNullObject

この段落が属するリストを取得します。 段落がリスト内にない場合、このメソッドは isNullObject プロパティが true に設定されたオブジェクトを返します。 詳細については、「 *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

段落を格納しているコンテンツ コントロールを取得します。 親コンテンツ コントロールがない場合、このメソッドは、 isNullObject プロパティが true に設定されたオブジェクトを返します。 詳細については、「 *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

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

readonly parentTableCellOrNullObject: Word.TableCell;

プロパティ値

注釈

API セット: WordApi 1.3

parentTableOrNullObject

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

readonly parentTableOrNullObject: Word.Table;

プロパティ値

注釈

API セット: WordApi 1.3

rightIndent

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

rightIndent: number;

プロパティ値

number

注釈

API セット: WordApi 1.1

shading

段落の網かけ形式を参照する ShadingUniversal オブジェクトを返します。

readonly shading: Word.ShadingUniversal;

プロパティ値

注釈

API セット: WordApiDesktop 1.3

shapes

インライン図形とフローティング図形の両方を含む、段落に固定されている Shape オブジェクトのコレクションを取得します。 現時点では、テキスト ボックス、幾何学的図形、グループ、画像、キャンバスの図形のみがサポートされています。

readonly shapes: Word.ShapeCollection;

プロパティ値

注釈

API セット: WordApiDesktop 1.2

重要: 時間の経過とともに、追加の種類の図形がサポートされる場合があることに注意してください。 そのため、アドインでは特定の種類の図形を要求および処理する必要があります。

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 = (document.getElementById("style-name-to-use") as HTMLInputElement).value;
  if (styleName == "") {
    console.warn("Enter a style name to apply.");
    return;
  }

  const style: Word.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: Word.Body = context.document.body;
    body.clear();
    body.insertParagraph(
      "Do you want to create a solution that extends the functionality of Word? You can use the Office Add-ins platform to extend Word clients running on the web, on a Windows desktop, or on a Mac.",
      "Start"
    );
    const paragraph: Word.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: Word.Paragraph = context.document.body.insertParagraph("Timeline", "End");
    paragraph.styleBuiltIn = "Heading2";
    const paragraph2: Word.Paragraph = 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: Word.Paragraph = 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: Word.Paragraph = context.document.body.insertParagraph("<Add Project Costs Here>", "End");
    paragraph4.styleBuiltIn = "Normal";
    paragraph4.font.highlightColor = "#FFFF00";
    const contentControl: Word.ContentControl = paragraph4.insertContentControl();
    contentControl.title = "ProjectCosts";
    const paragraph5: Word.Paragraph = context.document.body.insertParagraph("Project Team", "End");
    paragraph5.styleBuiltIn = "Heading2";
    paragraph5.font.highlightColor = "#FFFFFF";
    const paragraph6: Word.Paragraph = context.document.body.insertParagraph("Terms of Work", "End");
    paragraph6.styleBuiltIn = "Heading1";
    const paragraph7: Word.Paragraph = context.document.body.insertParagraph("Contractor shall provide the Services and Deliverable(s) as follows:", "End");
    paragraph7.styleBuiltIn = "Normal";
    const paragraph8: Word.Paragraph = context.document.body.insertParagraph("Out-of-Pocket Expenses / Invoice Procedures", "End");
    paragraph8.styleBuiltIn = "Heading2";
    const paragraph9 : Word.Paragraph= 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: Word.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);
  eventContexts[6] = context.document.onAnnotationPopupAction.add(onPopupActionHandler);

  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}: ID ${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()

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

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

closeUp()

段落の前のスペースを削除します。

closeUp(): void;

返品

void

注釈

API セット: WordApiDesktop 1.4

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

重要: 基になるサービスの要件により、この API が正常に動作するには Microsoft 365 サブスクリプションが必要です。 詳細については、 GitHub の問題 4953 を参照してください。

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

Paragraph オブジェクトの HTML 表現を取得します。 Web ページまたは HTML ビューアーで表示すると、書式設定はドキュメントの書式設定とほぼ一致しますが、完全ではありません。 このメソッドでは、異なるプラットフォーム (Windows、Mac、Web 上の Word など) 上の同じドキュメントに対してまったく同じ HTML は返されません。 プラットフォーム間で正確な忠実性や一貫性が必要な場合は、 Paragraph.getOoxml() を使用して返される XML を 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()

次の段落を取得します。 段落が最後の段落の場合、このメソッドは isNullObject プロパティが true に設定されたオブジェクトを返します。 詳細については、「 *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()

前の段落を取得します。 段落が最初の段落の場合、このメソッドは isNullObject プロパティが true に設定されたオブジェクトを返します。 詳細については、「 *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"

省略可能。 範囲の場所は、 wholestartendafter、または 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: Word.RangeCollection = 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: Word.RangeCollection = 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(changeTrackingVersion)

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

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

パラメーター

changeTrackingVersion

"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

indent()

段落を 1 レベルインデントします。

indent(): void;

返品

void

注釈

API セット: WordApiDesktop 1.4

indentCharacterWidth(count)

指定した文字数だけ段落をインデントします。

indentCharacterWidth(count: number): void;

パラメーター

count

number

インデントの文字数。

返品

void

注釈

API セット: WordApiDesktop 1.4

indentFirstLineCharacterWidth(count)

段落の最初の行を指定された文字数だけインデントします。

indentFirstLineCharacterWidth(count: number): void;

パラメーター

count

number

1 行目のインデントの文字数。

返品

void

注釈

API セット: WordApiDesktop 1.4

insertAnnotations(annotations)

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

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

パラメーター

annotations
Word.AnnotationSet

設定する注釈。

返品

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

注釈

API セット: WordApi 1.7

重要: 基になるサービスの要件により、この API が正常に動作するには Microsoft 365 サブスクリプションが必要です。 詳細については、 GitHub の問題 4953 を参照してください。

// 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: Word.Paragraph = context.document.getSelection().paragraphs.getFirst();
  const options: Word.CritiquePopupOptions = {
    brandingTextResourceId: "PG.TabLabel",
    subtitleResourceId: "PG.HelpCommand.TipTitle",
    titleResourceId: "PG.HelpCommand.Label",
    suggestions: ["suggestion 1", "suggestion 2", "suggestion 3"]
  };
  const critique1: Word.Critique = {
    colorScheme: Word.CritiqueColorScheme.red,
    start: 1,
    length: 3,
    popupOptions: options
  };
  const critique2: Word.Critique = {
    colorScheme: Word.CritiqueColorScheme.green,
    start: 6,
    length: 1,
    popupOptions: options
  };
  const critique3: Word.Critique = {
    colorScheme: Word.CritiqueColorScheme.blue,
    start: 10,
    length: 3,
    popupOptions: options
  };
  const critique4: Word.Critique = {
    colorScheme: Word.CritiqueColorScheme.lavender,
    start: 14,
    length: 3,
    popupOptions: options
  };
  const critique5: Word.Critique = {
    colorScheme: Word.CritiqueColorScheme.berry,
    start: 18,
    length: 10,
    popupOptions: options
  };
  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

// 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");
});

insertCanvas(insertShapeOptions)

アンカーを段落の先頭に配置して、テキストの前にフローティング キャンバスを挿入します。

insertCanvas(insertShapeOptions?: Word.InsertShapeOptions): Word.Shape;

パラメーター

insertShapeOptions
Word.InsertShapeOptions

省略可能。 キャンバスの位置とサイズ。 既定の場所とサイズは (0, 0, 300, 200) です。

返品

注釈

API セット: WordApiDesktop 1.2

insertContentControl(contentControlType)

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

insertContentControl(contentControlType?: Word.ContentControlType.richText | Word.ContentControlType.plainText | Word.ContentControlType.checkBox | Word.ContentControlType.dropDownList | Word.ContentControlType.comboBox | Word.ContentControlType.buildingBlockGallery | Word.ContentControlType.datePicker | Word.ContentControlType.repeatingSection | Word.ContentControlType.picture | Word.ContentControlType.group | "RichText" | "PlainText" | "CheckBox" | "DropDownList" | "ComboBox" | "BuildingBlockGallery" | "DatePicker" | "RepeatingSection" | "Picture" | "Group"): Word.ContentControl;

パラメーター

contentControlType

richText | plainText | checkBox | dropDownList | comboBox | buildingBlockGallery | datePicker | repeatingSection | picture | group | "RichText" | "PlainText" | "CheckBox" | "DropDownList" | "ComboBox" | "BuildingBlockGallery" | "DatePicker" | "RepeatingSection" | "Picture" | "Group"

省略可能。 挿入するコンテンツ コントロールの種類。 richText plainTextcheckBoxdropDownListcomboBoxbuildingBlockGallerydatePickerrepeatingSectionpicture、または group である必要があります。 既定値は richText です。

返品

注釈

API セット: WordApi 1.1

注: contentControlType パラメーターは WordApi 1.5 で導入されました。 plainText サポートは WordApi 1.5 で追加されました。 checkBox サポートは WordApi 1.7 で追加されました。 dropDownList comboBoxサポートは WordApi 1.9 で追加されました。 buildingBlockGallery datePickergrouppicturerepeatingSection のサポートは、WordApiDesktop 1.3 で追加されました。

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/10-content-controls/insert-and-change-content-controls.yaml

// Traverses each paragraph of the document and wraps a content control on each with either a even or odd tags.
await Word.run(async (context) => {
  let paragraphs = context.document.body.paragraphs;
  paragraphs.load("$none"); // Don't need any properties; just wrap each paragraph with a content control.

  await context.sync();

  for (let i = 0; i < paragraphs.items.length; i++) {
    let contentControl = paragraphs.items[i].insertContentControl();
    // For even, tag "even".
    if (i % 2 === 0) {
      contentControl.tag = "even";
    } else {
      contentControl.tag = "odd";
    }
  }
  console.log("Content controls inserted: " + paragraphs.items.length);

  await context.sync();
});

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"

値は、 replacestart、または end である必要があります。

返品

注釈

API セット: WordApi 1.1

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

insertGeometricShape(geometricShapeType, insertShapeOptions)

テキストの前に幾何学図形を挿入し、アンカーを段落の先頭に配置します。

insertGeometricShape(geometricShapeType: Word.GeometricShapeType, insertShapeOptions?: Word.InsertShapeOptions): Word.Shape;

パラメーター

geometricShapeType
Word.GeometricShapeType

挿入する図形の幾何学的タイプ。

insertShapeOptions
Word.InsertShapeOptions

省略可能。 幾何学的図形の位置とサイズ。 既定の場所とサイズは (0, 0, 100, 100) です。

返品

注釈

API セット: WordApiDesktop 1.2

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/45-shapes/group-ungroup.yaml

await Word.run(async (context) => {
  const body: Word.Body = context.document.body;
  body.clear();
  const lastParagraph: Word.Paragraph = body.paragraphs.getLast();

  // Inserts a text box.
  const textBoxOptions: Word.InsertShapeOptions = {
    top: 0,
    left: 0,
    height: 100,
    width: 100,
  };
  lastParagraph.insertTextBox("placeholder text", textBoxOptions);

  // Inserts a geometric shape.
  const geometricShapeOptions: Word.InsertShapeOptions = {
    height: 120,
    width: 120,
    left: 120,
  };
  lastParagraph.insertGeometricShape(Word.GeometricShapeType.star24, geometricShapeOptions);

  // Inserts a picture.
  const pictureOptions: Word.InsertShapeOptions = {
    top: 120,
    left: 60,
    height: 150,
    width: 150,
  };
  lastParagraph.insertPictureFromBase64(getPictureBase64(), pictureOptions);

  await context.sync();
});

insertGeometricShape(geometricShapeType, insertShapeOptions)

テキストの前に幾何学図形を挿入し、アンカーを段落の先頭に配置します。

insertGeometricShape(geometricShapeType: "LineInverse" | "Triangle" | "RightTriangle" | "Rectangle" | "Diamond" | "Parallelogram" | "Trapezoid" | "NonIsoscelesTrapezoid" | "Pentagon" | "Hexagon" | "Heptagon" | "Octagon" | "Decagon" | "Dodecagon" | "Star4" | "Star5" | "Star6" | "Star7" | "Star8" | "Star10" | "Star12" | "Star16" | "Star24" | "Star32" | "RoundRectangle" | "Round1Rectangle" | "Round2SameRectangle" | "Round2DiagonalRectangle" | "SnipRoundRectangle" | "Snip1Rectangle" | "Snip2SameRectangle" | "Snip2DiagonalRectangle" | "Plaque" | "Ellipse" | "Teardrop" | "HomePlate" | "Chevron" | "PieWedge" | "Pie" | "BlockArc" | "Donut" | "NoSmoking" | "RightArrow" | "LeftArrow" | "UpArrow" | "DownArrow" | "StripedRightArrow" | "NotchedRightArrow" | "BentUpArrow" | "LeftRightArrow" | "UpDownArrow" | "LeftUpArrow" | "LeftRightUpArrow" | "QuadArrow" | "LeftArrowCallout" | "RightArrowCallout" | "UpArrowCallout" | "DownArrowCallout" | "LeftRightArrowCallout" | "UpDownArrowCallout" | "QuadArrowCallout" | "BentArrow" | "UturnArrow" | "CircularArrow" | "LeftCircularArrow" | "LeftRightCircularArrow" | "CurvedRightArrow" | "CurvedLeftArrow" | "CurvedUpArrow" | "CurvedDownArrow" | "SwooshArrow" | "Cube" | "Can" | "LightningBolt" | "Heart" | "Sun" | "Moon" | "SmileyFace" | "IrregularSeal1" | "IrregularSeal2" | "FoldedCorner" | "Bevel" | "Frame" | "HalfFrame" | "Corner" | "DiagonalStripe" | "Chord" | "Arc" | "LeftBracket" | "RightBracket" | "LeftBrace" | "RightBrace" | "BracketPair" | "BracePair" | "Callout1" | "Callout2" | "Callout3" | "AccentCallout1" | "AccentCallout2" | "AccentCallout3" | "BorderCallout1" | "BorderCallout2" | "BorderCallout3" | "AccentBorderCallout1" | "AccentBorderCallout2" | "AccentBorderCallout3" | "WedgeRectCallout" | "WedgeRRectCallout" | "WedgeEllipseCallout" | "CloudCallout" | "Cloud" | "Ribbon" | "Ribbon2" | "EllipseRibbon" | "EllipseRibbon2" | "LeftRightRibbon" | "VerticalScroll" | "HorizontalScroll" | "Wave" | "DoubleWave" | "Plus" | "FlowChartProcess" | "FlowChartDecision" | "FlowChartInputOutput" | "FlowChartPredefinedProcess" | "FlowChartInternalStorage" | "FlowChartDocument" | "FlowChartMultidocument" | "FlowChartTerminator" | "FlowChartPreparation" | "FlowChartManualInput" | "FlowChartManualOperation" | "FlowChartConnector" | "FlowChartPunchedCard" | "FlowChartPunchedTape" | "FlowChartSummingJunction" | "FlowChartOr" | "FlowChartCollate" | "FlowChartSort" | "FlowChartExtract" | "FlowChartMerge" | "FlowChartOfflineStorage" | "FlowChartOnlineStorage" | "FlowChartMagneticTape" | "FlowChartMagneticDisk" | "FlowChartMagneticDrum" | "FlowChartDisplay" | "FlowChartDelay" | "FlowChartAlternateProcess" | "FlowChartOffpageConnector" | "ActionButtonBlank" | "ActionButtonHome" | "ActionButtonHelp" | "ActionButtonInformation" | "ActionButtonForwardNext" | "ActionButtonBackPrevious" | "ActionButtonEnd" | "ActionButtonBeginning" | "ActionButtonReturn" | "ActionButtonDocument" | "ActionButtonSound" | "ActionButtonMovie" | "Gear6" | "Gear9" | "Funnel" | "MathPlus" | "MathMinus" | "MathMultiply" | "MathDivide" | "MathEqual" | "MathNotEqual" | "CornerTabs" | "SquareTabs" | "PlaqueTabs" | "ChartX" | "ChartStar" | "ChartPlus", insertShapeOptions?: Word.InsertShapeOptions): Word.Shape;

パラメーター

geometricShapeType

"LineInverse" | "Triangle" | "RightTriangle" | "Rectangle" | "Diamond" | "Parallelogram" | "Trapezoid" | "NonIsoscelesTrapezoid" | "Pentagon" | "Hexagon" | "Heptagon" | "Octagon" | "Decagon" | "Dodecagon" | "Star4" | "Star5" | "Star6" | "Star7" | "Star8" | "Star10" | "Star12" | "Star16" | "Star24" | "Star32" | "RoundRectangle" | "Round1Rectangle" | "Round2SameRectangle" | "Round2DiagonalRectangle" | "SnipRoundRectangle" | "Snip1Rectangle" | "Snip2SameRectangle" | "Snip2DiagonalRectangle" | "Plaque" | "Ellipse" | "Teardrop" | "HomePlate" | "Chevron" | "PieWedge" | "Pie" | "BlockArc" | "Donut" | "NoSmoking" | "RightArrow" | "LeftArrow" | "UpArrow" | "DownArrow" | "StripedRightArrow" | "NotchedRightArrow" | "BentUpArrow" | "LeftRightArrow" | "UpDownArrow" | "LeftUpArrow" | "LeftRightUpArrow" | "QuadArrow" | "LeftArrowCallout" | "RightArrowCallout" | "UpArrowCallout" | "DownArrowCallout" | "LeftRightArrowCallout" | "UpDownArrowCallout" | "QuadArrowCallout" | "BentArrow" | "UturnArrow" | "CircularArrow" | "LeftCircularArrow" | "LeftRightCircularArrow" | "CurvedRightArrow" | "CurvedLeftArrow" | "CurvedUpArrow" | "CurvedDownArrow" | "SwooshArrow" | "Cube" | "Can" | "LightningBolt" | "Heart" | "Sun" | "Moon" | "SmileyFace" | "IrregularSeal1" | "IrregularSeal2" | "FoldedCorner" | "Bevel" | "Frame" | "HalfFrame" | "Corner" | "DiagonalStripe" | "Chord" | "Arc" | "LeftBracket" | "RightBracket" | "LeftBrace" | "RightBrace" | "BracketPair" | "BracePair" | "Callout1" | "Callout2" | "Callout3" | "AccentCallout1" | "AccentCallout2" | "AccentCallout3" | "BorderCallout1" | "BorderCallout2" | "BorderCallout3" | "AccentBorderCallout1" | "AccentBorderCallout2" | "AccentBorderCallout3" | "WedgeRectCallout" | "WedgeRRectCallout" | "WedgeEllipseCallout" | "CloudCallout" | "Cloud" | "Ribbon" | "Ribbon2" | "EllipseRibbon" | "EllipseRibbon2" | "LeftRightRibbon" | "VerticalScroll" | "HorizontalScroll" | "Wave" | "DoubleWave" | "Plus" | "FlowChartProcess" | "FlowChartDecision" | "FlowChartInputOutput" | "FlowChartPredefinedProcess" | "FlowChartInternalStorage" | "FlowChartDocument" | "FlowChartMultidocument" | "FlowChartTerminator" | "FlowChartPreparation" | "FlowChartManualInput" | "FlowChartManualOperation" | "FlowChartConnector" | "FlowChartPunchedCard" | "FlowChartPunchedTape" | "FlowChartSummingJunction" | "FlowChartOr" | "FlowChartCollate" | "FlowChartSort" | "FlowChartExtract" | "FlowChartMerge" | "FlowChartOfflineStorage" | "FlowChartOnlineStorage" | "FlowChartMagneticTape" | "FlowChartMagneticDisk" | "FlowChartMagneticDrum" | "FlowChartDisplay" | "FlowChartDelay" | "FlowChartAlternateProcess" | "FlowChartOffpageConnector" | "ActionButtonBlank" | "ActionButtonHome" | "ActionButtonHelp" | "ActionButtonInformation" | "ActionButtonForwardNext" | "ActionButtonBackPrevious" | "ActionButtonEnd" | "ActionButtonBeginning" | "ActionButtonReturn" | "ActionButtonDocument" | "ActionButtonSound" | "ActionButtonMovie" | "Gear6" | "Gear9" | "Funnel" | "MathPlus" | "MathMinus" | "MathMultiply" | "MathDivide" | "MathEqual" | "MathNotEqual" | "CornerTabs" | "SquareTabs" | "PlaqueTabs" | "ChartX" | "ChartStar" | "ChartPlus"

挿入する図形の幾何学的タイプ。

insertShapeOptions
Word.InsertShapeOptions

省略可能。 幾何学的図形の位置とサイズ。 既定の場所とサイズは (0, 0, 100, 100) です。

返品

注釈

API セット: WordApiDesktop 1.2

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"

値は、 replacestart、または 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"

値は、 replacestart、または 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"

値は、 replacestart、または 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

insertPictureFromBase64(base64EncodedImage, insertShapeOptions)

アンカーを段落の先頭に配置して、テキストの前に浮動画像を挿入します。

insertPictureFromBase64(base64EncodedImage: string, insertShapeOptions?: Word.InsertShapeOptions): Word.Shape;

パラメーター

base64EncodedImage

string

挿入する Base64 でエンコードされた画像。

insertShapeOptions
Word.InsertShapeOptions

省略可能。 画像の場所とサイズ。 既定の場所は (0, 0) で、既定のサイズは画像の元のサイズです。

返品

注釈

API セット: WordApiDesktop 1.2

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"

値は、 replacestart、または 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: Word.Range = context.document.body.paragraphs.getLast().insertText("Just replaced the last paragraph!", "Replace");
  range.font.highlightColor = "black";
  range.font.color = "white";

  await context.sync();
});

insertTextBox(text, insertShapeOptions)

テキストの前にフローティング テキスト ボックスを挿入し、アンカーを段落の先頭に配置します。

insertTextBox(text?: string, insertShapeOptions?: Word.InsertShapeOptions): Word.Shape;

パラメーター

text

string

省略可能。 テキスト ボックスに挿入するテキスト。

insertShapeOptions
Word.InsertShapeOptions

省略可能。 テキスト ボックスの場所とサイズ。 既定の場所とサイズは (0, 0, 100, 100) です。

返品

注釈

API セット: WordApiDesktop 1.2

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/45-shapes/manage-shapes-text-boxes.yaml

await Word.run(async (context) => {
  // Inserts a text box at the beginning of the first paragraph in the header.
  const headerFooterBody: Word.Body = context.document.sections.getFirst().getHeader(Word.HeaderFooterType.primary);
  headerFooterBody.load("paragraphs");
  const firstParagraph: Word.Paragraph = headerFooterBody.paragraphs.getFirst();
  const insertShapeOptions: Word.InsertShapeOptions = {
    top: 0,
    left: 0,
    height: 100,
    width: 100
  };
  const newTextBox: Word.Shape = firstParagraph.insertTextBox("placeholder text", insertShapeOptions);
  newTextBox.select();
  await context.sync();

  console.log("Inserted a text box at the beginning of the first paragraph in the header.");
});

joinList()

この段落の上または下に最も近いリストを持つリスト段落を結合します。

joinList(): void;

返品

void

注釈

API セット: WordApiDesktop 1.4

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 は読み込むナビゲーションのプロパティを指定するコンマ区切りの文字列です。

返品

next(count)

次の段落を示す Paragraph オブジェクトを返します。

next(count: number): Word.Paragraph;

パラメーター

count

number

省略可能。 先に進む段落数。

返品

注釈

API セット: WordApiDesktop 1.4

openOrCloseUp()

段落の前の間隔を切り替えます。

openOrCloseUp(): void;

返品

void

注釈

API セット: WordApiDesktop 1.4

openUp()

段落前の間隔を 12 ポイントに設定します。

openUp(): void;

返品

void

注釈

API セット: WordApiDesktop 1.4

outdent()

段落のインデントを 1 レベル削除します。

outdent(): void;

返品

void

注釈

API セット: WordApiDesktop 1.4

outlineDemote()

次の見出しレベル スタイル (見出し 1 から見出し 8) を段落に適用します。

outlineDemote(): void;

返品

void

注釈

API セット: WordApiDesktop 1.4

outlineDemoteToBody()

標準スタイルを適用して、段落を本文テキストに降格します。

outlineDemoteToBody(): void;

返品

void

注釈

API セット: WordApiDesktop 1.4

outlinePromote()

前の見出しレベル スタイル (見出し 1 から見出し 8) を段落に適用します。

outlinePromote(): void;

返品

void

注釈

API セット: WordApiDesktop 1.4

previous(count)

前の段落を Paragraph オブジェクトとして返します。

previous(count: number): Word.Paragraph;

パラメーター

count

number

省略可能。 後方に移動する段落の数。

返品

注釈

API セット: WordApiDesktop 1.4

reset()

手動で指定した段落書式 (スタイルを使わずに設定した書式) を削除します。

reset(): void;

返品

void

注釈

API セット: WordApiDesktop 1.4

resetAdvanceTo()

カスタム リスト レベルを使用する段落を元のレベル設定にリセットします。

resetAdvanceTo(): void;

返品

void

注釈

API セット: WordApiDesktop 1.4

search(searchText, searchOptions)

Paragraph オブジェクトのスコープに対して、指定された検索オプションを使用して検索を実行します。 検索結果は、 Range オブジェクトのコレクションです。

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

省略可能。 選択モードは、 selectstart、または 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(selectionMode)

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

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

パラメーター

selectionMode

"Select" | "Start" | "End"

省略可能。 選択モードは、 selectstart、または end である必要があります。 select が既定です。

返品

void

注釈

API セット: WordApi 1.1

selectNumber()

箇条書きの段落番号または行頭文字を選択します。

selectNumber(): void;

返品

void

注釈

API セット: WordApiDesktop 1.4

separateList()

1 つのリストを 2 つのリストに分割します。 段落番号の場合、新しいリストは開始番号 (通常 1) から番号付けが再開されます。

separateList(): void;

返品

void

注釈

API セット: WordApiDesktop 1.4

set(properties, options)

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

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

パラメーター

properties
Word.Interfaces.ParagraphUpdateData

メソッドが呼び出されたオブジェクトのプロパティと同型構造のプロパティを持つ JavaScript オブジェクト。

options
OfficeExtension.UpdateOptions

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

返品

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: Word.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: Word.Paragraph = context.document.body.paragraphs.getFirst();
  const secondParagraph: Word.Paragraph = 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

space1()

段落をシングル スペースに設定します。

space1(): void;

返品

void

注釈

API セット: WordApiDesktop 1.4

space1Pt5()

段落を 1.5 行間隔に設定します。

space1Pt5(): void;

返品

void

注釈

API セット: WordApiDesktop 1.4

space2()

段落をダブル スペースに設定します。

space2(): void;

返品

void

注釈

API セット: WordApiDesktop 1.4

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: Word.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: Word.ParagraphCollection = context.document.body.paragraphs;
  paragraphs.load("$none");

  await context.sync();

  // Start new list using the second paragraph.
  const list: Word.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: Word.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();
});

tabHangingIndent(count)

指定されたタブ位置にぶら下げインデントを設定します。

tabHangingIndent(count: number): void;

パラメーター

count

number

ぶら下げているインデントのタブ位置の数。

返品

void

注釈

API セット: WordApiDesktop 1.4

tabIndent(count)

段落の左インデントを、指定したタブ位置の数に設定します。

tabIndent(count: number): void;

パラメーター

count

number

左インデントのタブ位置の数。

返品

void

注釈

API セット: WordApiDesktop 1.4

toJSON()

API オブジェクトが JSON.stringify() に渡されるときに、より有用な出力を提供するために、JavaScript toJSON() メソッドをオーバーライドします。 (次に、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 ベータ版 (プレビューのみ)

onCommentChanged

注意

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

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

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

イベントの種類

注釈

API セット: WordApi ベータ版 (プレビューのみ)

onCommentDeleted

注意

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

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

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

イベントの種類

注釈

API セット: WordApi ベータ版 (プレビューのみ)

onCommentDeselected

注意

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

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

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

イベントの種類

注釈

API セット: WordApi ベータ版 (プレビューのみ)

onCommentSelected

注意

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

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

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

イベントの種類

注釈

API セット: WordApi ベータ版 (プレビューのみ)