Word.Range class
文書内の連続した領域を表します。
- Extends
注釈
プロパティ
content |
範囲内のコンテンツ コントロール オブジェクトのコレクションを取得します。 |
context | オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。 |
endnotes | 範囲内の文末脚注のコレクションを取得します。 |
fields | 範囲内のフィールド オブジェクトのコレクションを取得します。 |
font | 範囲のテキスト形式を取得します。 これを使用して、フォント名、サイズ、色、およびその他のプロパティを取得および設定します。 |
footnotes | 範囲内の脚注のコレクションを取得します。 |
hyperlink | 範囲内の最初のハイパーリンクを取得するか、または範囲にハイパーリンクを設定します。 範囲に新しいハイパーリンクを設定すると、範囲内のすべてのハイパーリンクが削除されます。 '#' を使用して、アドレス部分をオプションの場所部分から分離します。 |
inline |
範囲に含まれるインライン画像オブジェクトのコレクションを取得します。 |
is |
範囲の長さが 0 であるかどうかを確認します。 |
lists | 範囲内のリスト オブジェクトのコレクションを取得します。 |
paragraphs | 範囲内の段落オブジェクトのコレクションを取得します。 |
parent |
範囲の親の本文を取得します。 |
parent |
範囲を含む現在サポートされているコンテンツ コントロールを取得します。 |
parent |
範囲を含む現在サポートされているコンテンツ コントロールを取得します。 親コンテンツ コントロールがない場合、このメソッドは プロパティが に設定されたオブジェクトを |
parent |
範囲を含むテーブルを取得します。 テーブルに |
parent |
範囲を含むテーブルのセルを取得します。 テーブル セルに |
parent |
範囲を含むテーブルのセルを取得します。 テーブル セルに含まれていない場合、このメソッドは プロパティが に設定されたオブジェクトを |
parent |
範囲を含むテーブルを取得します。 テーブルに含まれていない場合、このメソッドは プロパティが に設定されたオブジェクトを |
style | 範囲のスタイル名を指定します。 カスタム スタイルとローカライズされたスタイルの名前には、このプロパティを使用します。 ロケール間で移植可能な組み込みスタイルを使用するには、"styleBuiltIn" プロパティを参照してください。 |
style |
範囲の組み込みスタイル名を指定します。 ロケール間で移植可能な組み込みスタイルの場合は、このプロパティを使用します。 カスタム スタイルまたはローカライズされたスタイルの名前を使用するには、"style" プロパティを参照してください。 |
tables | 範囲内のテーブル オブジェクトのコレクションを取得します。 |
text | 範囲のテキストを取得します。 |
メソッド
clear() | 範囲オブジェクトの内容をクリアします。 ユーザーは、消去された内容を元に戻す操作を実行できます。 |
compare |
この範囲の場所を別の範囲の場所と比較します。 |
delete() | 文書から範囲と、その範囲の内容を削除します。 |
expand |
別の範囲を対象にするために、いずれかの方向でこの範囲から拡張する新しい範囲を返します。 この範囲は変更されません。 |
expand |
別の範囲を対象にするために、いずれかの方向でこの範囲から拡張する新しい範囲を返します。 この範囲は変更されません。 2 つの範囲に和集合がない場合、このメソッドは プロパティが に設定されたオブジェクトを |
get |
範囲内のすべてのブックマークまたは範囲の重複する名前を取得します。 名前がアンダースコア文字で始まる場合、ブックマークは非表示になります。 |
get |
範囲に関連付けられているコメントを取得します。 |
get |
範囲内で現在サポートされているコンテンツ コントロールを取得します。 |
get |
範囲オブジェクトの HTML 表現を取得します。 Web ページまたは HTML ビューアーでレンダリングされた場合、書式設定は、ドキュメントの書式設定と完全に一致しませんが、近い形式になります。 このメソッドは、異なるプラットフォーム (Windows、Mac、web 上のWordなど) 上の同じドキュメントに対してまったく同じ HTML を返しません。 正確な忠実性、またはプラットフォーム間の整合性が必要な場合は、返された XML を使用 |
get |
範囲内のハイパーリンクの子の範囲を取得します。 |
get |
句読点やその他の終了記号を使用して、次のテキスト範囲を取得します。 このテキスト範囲が |
get |
句読点やその他の終了記号を使用して、次のテキスト範囲を取得します。 このテキスト範囲が最後のテキスト範囲の場合、このメソッドは プロパティが に設定されたオブジェクトを |
get |
Range オブジェクトの OOXML 表記を取得します。 |
get |
範囲の複製を作成するか、新しい範囲として開始点または終了点を取得します。 |
get |
ChangeTrackingVersion の選択に基づいて、レビューされたテキストを取得します。 |
get |
ChangeTrackingVersion の選択に基づいて、レビューされたテキストを取得します。 |
get |
句読点やその他の終了記号を使用して、範囲内のテキストの子範囲を取得します。 |
get |
範囲内の TrackedChange オブジェクトのコレクションを取得します。 |
insert |
範囲にブックマークを挿入します。 同じ名前のブックマークがどこかに存在する場合は、最初に削除されます。 |
insert |
メイン文書の指定した位置に、区切りを挿入します。 |
insert |
範囲にコメントを挿入します。 |
insert |
Range オブジェクトをコンテンツ コントロールでラップします。 |
insert |
文末脚注を挿入します。 文末脚注の参照は、範囲の後に配置されます。 |
insert |
指定した場所にフィールドを挿入します。 |
insert |
指定した場所にフィールドを挿入します。 |
insert |
指定した位置に文書を挿入します。 |
insert |
脚注を挿入します。 脚注の参照は、範囲の後に配置されます。 |
insert |
指定した位置に HTML を挿入します。 |
insert |
指定された位置に画像を挿入します。 |
insert |
指定した位置に OOXML を挿入します。 |
insert |
指定した位置に、段落を挿入します。 |
insert |
指定した数の行と列を含むテーブルを挿入します。 |
insert |
指定した位置にテキストを挿入します。 |
intersect |
別の範囲とこの範囲の交点として、新しい範囲を返します。 この範囲は変更されません。 |
intersect |
別の範囲とこの範囲の交点として、新しい範囲を返します。 この範囲は変更されません。 2 つの範囲が重複または隣接していない場合、このメソッドは プロパティが に設定されたオブジェクトを |
load(options) | オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、 |
load(property |
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、 |
load(property |
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、 |
search(search |
範囲オブジェクトのスコープで、指定した SearchOptions を使用して検索を実行します。 検索結果は、範囲オブジェクトのコレクションです。 |
select(selection |
範囲を選択して、その範囲に Word の UI を移動します。 |
select(selection |
範囲を選択して、その範囲に Word の UI を移動します。 |
set(properties, options) | オブジェクトの複数のプロパティを同時に設定します。 適切なプロパティを持つプレーン オブジェクトまたは同じ型の別の API オブジェクトを渡すことができます。 |
set(properties) | 既存の読み込まれたオブジェクトに基づいて、オブジェクトに複数のプロパティを同時に設定します。 |
split(delimiters, multi |
区切り記号を使用して、範囲を子の範囲に分割します。 |
toJSON() | API オブジェクトが に渡されたときにより便利な出力を提供するために、JavaScript |
track() | ドキュメントの環境変更に基づいて自動的に調整する目的でオブジェクトを追跡します。 この呼び出しは、context.trackedObjects.add(thisObject)の短縮形です。 このオブジェクトを呼び出しで |
untrack() | 前に追跡されていた場合、このオブジェクトに関連付けられているメモリを解放します。 この呼び出しは、context.trackedObjects.remove(thisObject)の短縮形です。 追跡対象オブジェクトが多いとホスト アプリケーションの動作が遅くなります。追加したオブジェクトが不要になったら、必ずそれを解放してください。 メモリ解放が有効になる前に を呼び出す |
プロパティの詳細
contentControls
範囲内のコンテンツ コントロール オブジェクトのコレクションを取得します。
readonly contentControls: Word.ContentControlCollection;
プロパティ値
注釈
context
オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。
context: RequestContext;
プロパティ値
endnotes
範囲内の文末脚注のコレクションを取得します。
readonly endnotes: Word.NoteItemCollection;
プロパティ値
注釈
fields
範囲内のフィールド オブジェクトのコレクションを取得します。
readonly fields: Word.FieldCollection;
プロパティ値
注釈
font
範囲のテキスト形式を取得します。 これを使用して、フォント名、サイズ、色、およびその他のプロパティを取得および設定します。
readonly font: Word.Font;
プロパティ値
注釈
footnotes
範囲内の脚注のコレクションを取得します。
readonly footnotes: Word.NoteItemCollection;
プロパティ値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-footnotes.yaml
// Gets the footnotes in the selected document range.
await Word.run(async (context) => {
const footnotes = context.document.getSelection().footnotes;
footnotes.load("length");
await context.sync();
console.log("Number of footnotes in the selected range: " + footnotes.items.length);
});
hyperlink
範囲内の最初のハイパーリンクを取得するか、または範囲にハイパーリンクを設定します。 範囲に新しいハイパーリンクを設定すると、範囲内のすべてのハイパーリンクが削除されます。 '#' を使用して、アドレス部分をオプションの場所部分から分離します。
hyperlink: string;
プロパティ値
string
注釈
inlinePictures
範囲に含まれるインライン画像オブジェクトのコレクションを取得します。
readonly inlinePictures: Word.InlinePictureCollection;
プロパティ値
注釈
isEmpty
lists
範囲内のリスト オブジェクトのコレクションを取得します。
readonly lists: Word.ListCollection;
プロパティ値
注釈
paragraphs
範囲内の段落オブジェクトのコレクションを取得します。
readonly paragraphs: Word.ParagraphCollection;
プロパティ値
注釈
重要: 要件セット 1.1 と 1.2 の場合、この範囲内に完全に含まれるテーブル内の段落は返されません。 要件セット 1.3 から、そのようなテーブル内の段落も返されます。
parentBody
parentContentControl
範囲を含む現在サポートされているコンテンツ コントロールを取得します。 ItemNotFound
親コンテンツ コントロールがない場合は、エラーをスローします。
readonly parentContentControl: Word.ContentControl;
プロパティ値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/10-content-controls/insert-and-change-checkbox-content-control.yaml
// Toggles the isChecked property of the first checkbox content control found in the selection.
await Word.run(async (context) => {
const selectedRange = context.document.getSelection();
let selectedContentControl = selectedRange
.getContentControls({
types: [Word.ContentControlType.checkBox]
})
.getFirstOrNullObject();
selectedContentControl.load("id,checkboxContentControl/isChecked");
await context.sync();
if (selectedContentControl.isNullObject) {
const parentContentControl = selectedRange.parentContentControl;
parentContentControl.load("id,type,checkboxContentControl/isChecked");
await context.sync();
if (parentContentControl.isNullObject || parentContentControl.type !== Word.ContentControlType.checkBox) {
console.warn("No checkbox content control is currently selected.");
return;
} else {
selectedContentControl = parentContentControl;
}
}
const isCheckedBefore = selectedContentControl.checkboxContentControl.isChecked;
console.log("isChecked state before:", `id: ${selectedContentControl.id} ... isChecked: ${isCheckedBefore}`);
selectedContentControl.checkboxContentControl.isChecked = !isCheckedBefore;
selectedContentControl.load("id,checkboxContentControl/isChecked");
await context.sync();
console.log(
"isChecked state after:",
`id: ${selectedContentControl.id} ... isChecked: ${selectedContentControl.checkboxContentControl.isChecked}`
);
});
parentContentControlOrNullObject
範囲を含む現在サポートされているコンテンツ コントロールを取得します。 親コンテンツ コントロールがない場合、このメソッドは プロパティが に設定されたオブジェクトをisNullObject
true
返します。 詳細については、「 *OrNullObject メソッドとプロパティ」を参照してください。
readonly parentContentControlOrNullObject: Word.ContentControl;
プロパティ値
注釈
parentTable
範囲を含むテーブルを取得します。 テーブルに ItemNotFound
含まれていない場合は、エラーをスローします。
readonly parentTable: Word.Table;
プロパティ値
注釈
parentTableCell
範囲を含むテーブルのセルを取得します。 テーブル セルに ItemNotFound
含まれていない場合は、エラーをスローします。
readonly parentTableCell: Word.TableCell;
プロパティ値
注釈
parentTableCellOrNullObject
範囲を含むテーブルのセルを取得します。 テーブル セルに含まれていない場合、このメソッドは プロパティが に設定されたオブジェクトをisNullObject
true
返します。 詳細については、「 *OrNullObject メソッドとプロパティ」を参照してください。
readonly parentTableCellOrNullObject: Word.TableCell;
プロパティ値
注釈
parentTableOrNullObject
範囲を含むテーブルを取得します。 テーブルに含まれていない場合、このメソッドは プロパティが に設定されたオブジェクトをisNullObject
true
返します。 詳細については、「 *OrNullObject メソッドとプロパティ」を参照してください。
readonly parentTableOrNullObject: Word.Table;
プロパティ値
注釈
style
範囲のスタイル名を指定します。 カスタム スタイルとローカライズされたスタイルの名前には、このプロパティを使用します。 ロケール間で移植可能な組み込みスタイルを使用するには、"styleBuiltIn" プロパティを参照してください。
style: string;
プロパティ値
string
注釈
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"
注釈
例
// 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 header = context.document.body.insertText("This is a sample Heading 1 Title!!\n",
"Start" /*this means at the beginning of the body */);
header.styleBuiltIn = Word.BuiltInStyleName.heading1;
await context.sync();
});
tables
範囲内のテーブル オブジェクトのコレクションを取得します。
readonly tables: Word.TableCollection;
プロパティ値
注釈
text
メソッドの詳細
clear()
範囲オブジェクトの内容をクリアします。 ユーザーは、消去された内容を元に戻す操作を実行できます。
clear(): void;
戻り値
void
注釈
例
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
// Queue a command to get the current selection and then
// create a proxy range object with the results.
const range = context.document.getSelection();
// Queue a command to clear the contents of the proxy range object.
range.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 selection (range object)');
});
compareLocationWith(range)
この範囲の場所を別の範囲の場所と比較します。
compareLocationWith(range: Word.Range): OfficeExtension.ClientResult<Word.LocationRelation>;
パラメーター
- range
- Word.Range
必須。 この範囲と比較する範囲。
戻り値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/compare-location.yaml
// Compares the location of one paragraph in relation to another paragraph.
await Word.run(async (context) => {
const paragraphs = context.document.body.paragraphs;
paragraphs.load("items");
await context.sync();
const firstParagraphAsRange = paragraphs.items[0].getRange();
const secondParagraphAsRange = paragraphs.items[1].getRange();
const comparedLocation = firstParagraphAsRange.compareLocationWith(secondParagraphAsRange);
await context.sync();
console.log(`Location of the first paragraph in relation to the second paragraph: ${comparedLocation.value}`);
});
delete()
文書から範囲と、その範囲の内容を削除します。
delete(): void;
戻り値
void
注釈
例
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
// Queue a command to get the current selection and then
// create a proxy range object with the results.
const range = context.document.getSelection();
// Queue a command to delete the range object.
range.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 selection (range object)');
});
expandTo(range)
別の範囲を対象にするために、いずれかの方向でこの範囲から拡張する新しい範囲を返します。 この範囲は変更されません。 ItemNotFound
2 つの範囲に和集合がない場合は、エラーをスローします。
expandTo(range: Word.Range): Word.Range;
パラメーター
- range
- Word.Range
必須です。 別の範囲。
戻り値
注釈
expandToOrNullObject(range)
別の範囲を対象にするために、いずれかの方向でこの範囲から拡張する新しい範囲を返します。 この範囲は変更されません。 2 つの範囲に和集合がない場合、このメソッドは プロパティが に設定されたオブジェクトをisNullObject
true
返します。 詳細については、「 *OrNullObject メソッドとプロパティ」を参照してください。
expandToOrNullObject(range: Word.Range): Word.Range;
パラメーター
- range
- Word.Range
必須。 別の範囲。
戻り値
注釈
getBookmarks(includeHidden, includeAdjacent)
範囲内のすべてのブックマークまたは範囲の重複する名前を取得します。 名前がアンダースコア文字で始まる場合、ブックマークは非表示になります。
getBookmarks(includeHidden?: boolean, includeAdjacent?: boolean): OfficeExtension.ClientResult<string[]>;
パラメーター
- includeHidden
-
boolean
省略可能。 非表示のブックマークを含めるかどうかを示します。 既定値は false で、非表示のブックマークが除外されることを示します。
- includeAdjacent
-
boolean
省略可能。 範囲に隣接するブックマークを含めるかどうかを示します。 既定値は false で、隣接するブックマークが除外されることを示します。
戻り値
OfficeExtension.ClientResult<string[]>
注釈
getComments()
範囲に関連付けられているコメントを取得します。
getComments(): Word.CommentCollection;
戻り値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-comments.yaml
// Gets the comments in the selected content.
await Word.run(async (context) => {
const comments: Word.CommentCollection = context.document.getSelection().getComments();
// Load objects to log in the console.
comments.load();
await context.sync();
console.log("Comments:", comments);
});
getContentControls(options)
範囲内で現在サポートされているコンテンツ コントロールを取得します。
getContentControls(options?: Word.ContentControlOptions): Word.ContentControlCollection;
パラメーター
- options
- Word.ContentControlOptions
省略可能。 返されるコンテンツ コントロールを定義するオプション。
戻り値
注釈
重要: options パラメーターに特定の型が指定されている場合、サポートされている型のコンテンツ コントロールのみが返されます。 ジェネリック Wordのメソッドを使用すると、例外がスローされることに注意してください。特定の種類に関連しない ContentControl。 時間によっては、追加の種類のコンテンツ コントロールがサポートされる場合があります。 そのため、アドインは特定の種類のコンテンツ コントロールを要求して処理する必要があります。
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/10-content-controls/insert-and-change-checkbox-content-control.yaml
// Deletes the first checkbox content control found in the selection.
await Word.run(async (context) => {
const selectedRange = context.document.getSelection();
let selectedContentControl = selectedRange
.getContentControls({
types: [Word.ContentControlType.checkBox]
})
.getFirstOrNullObject();
selectedContentControl.load("id");
await context.sync();
if (selectedContentControl.isNullObject) {
const parentContentControl = selectedRange.parentContentControl;
parentContentControl.load("id,type");
await context.sync();
if (parentContentControl.isNullObject || parentContentControl.type !== Word.ContentControlType.checkBox) {
console.warn("No checkbox content control is currently selected.");
return;
} else {
selectedContentControl = parentContentControl;
}
}
console.log(`About to delete checkbox content control with id: ${selectedContentControl.id}`);
selectedContentControl.delete(false);
await context.sync();
console.log("Deleted checkbox content control.");
});
getHtml()
範囲オブジェクトの HTML 表現を取得します。 Web ページまたは HTML ビューアーでレンダリングされた場合、書式設定は、ドキュメントの書式設定と完全に一致しませんが、近い形式になります。 このメソッドは、異なるプラットフォーム (Windows、Mac、web 上のWordなど) 上の同じドキュメントに対してまったく同じ HTML を返しません。 正確な忠実性、またはプラットフォーム間の整合性が必要な場合は、返された XML を使用 Range.getOoxml()
して HTML に変換します。
getHtml(): OfficeExtension.ClientResult<string>;
戻り値
OfficeExtension.ClientResult<string>
注釈
例
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
// Queue a command to get the current selection and then
// create a proxy range object with the results.
const range = context.document.getSelection();
// Queue a command to get the HTML of the current selection.
const html = range.getHtml();
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
await context.sync();
console.log('The HTML read from the document was: ' + html.value);
});
getHyperlinkRanges()
範囲内のハイパーリンクの子の範囲を取得します。
getHyperlinkRanges(): Word.RangeCollection;
戻り値
注釈
例
await Word.run(async (context) => {
// Get the entire document body.
const bodyRange = context.document.body.getRange(Word.RangeLocation.whole);
// Get all the ranges that only consist of hyperlinks.
const hyperLinks = bodyRange.getHyperlinkRanges();
hyperLinks.load("hyperlink");
await context.sync();
// Log each hyperlink.
hyperLinks.items.forEach((linkRange) => {
console.log(linkRange.hyperlink);
});
});
getNextTextRange(endingMarks, trimSpacing)
句読点やその他の終了記号を使用して、次のテキスト範囲を取得します。 このテキスト範囲が ItemNotFound
最後のテキスト範囲である場合は、エラーをスローします。
getNextTextRange(endingMarks: string[], trimSpacing?: boolean): Word.Range;
パラメーター
- endingMarks
-
string[]
必須です。 句読点や他の終了記号を文字列の配列として指定します。
- trimSpacing
-
boolean
省略可能。 返される範囲の先頭と末尾から間隔文字 (スペース、タブ、列区切り、段落の終了記号) をトリミングするかどうかを示します。 既定値は false で、範囲の先頭と末尾の間隔文字が含まれていることを示します。
戻り値
注釈
getNextTextRangeOrNullObject(endingMarks, trimSpacing)
句読点やその他の終了記号を使用して、次のテキスト範囲を取得します。 このテキスト範囲が最後のテキスト範囲の場合、このメソッドは プロパティが に設定されたオブジェクトをisNullObject
true
返します。 詳細については、「 *OrNullObject メソッドとプロパティ」を参照してください。
getNextTextRangeOrNullObject(endingMarks: string[], trimSpacing?: boolean): Word.Range;
パラメーター
- endingMarks
-
string[]
必須です。 句読点や他の終了記号を文字列の配列として指定します。
- trimSpacing
-
boolean
省略可能。 返される範囲の先頭と末尾から間隔文字 (スペース、タブ、列区切り、段落の終了記号) をトリミングするかどうかを示します。 既定値は false で、範囲の先頭と末尾の間隔文字が含まれていることを示します。
戻り値
注釈
getOoxml()
Range オブジェクトの OOXML 表記を取得します。
getOoxml(): OfficeExtension.ClientResult<string>;
戻り値
OfficeExtension.ClientResult<string>
注釈
例
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
// Queue a command to get the current selection and then
// create a proxy range object with the results.
const range = context.document.getSelection();
// Queue a command to get the OOXML of the current selection.
const ooxml = range.getOoxml();
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
await context.sync();
console.log('The OOXML read from the document was: ' + ooxml.value);
});
getRange(rangeLocation)
範囲の複製を作成するか、新しい範囲として開始点または終了点を取得します。
getRange(rangeLocation?: Word.RangeLocation.whole | Word.RangeLocation.start | Word.RangeLocation.end | Word.RangeLocation.after | Word.RangeLocation.content | "Whole" | "Start" | "End" | "After" | "Content"): Word.Range;
パラメーター
- rangeLocation
-
whole | start | end | after | content | "Whole" | "Start" | "End" | "After" | "Content"
省略可能。 範囲の場所は、'Whole'、'Start'、'End'、'After'、または 'Content' である必要があります。
戻り値
注釈
getReviewedText(changeTrackingVersion)
ChangeTrackingVersion の選択に基づいて、レビューされたテキストを取得します。
getReviewedText(changeTrackingVersion?: Word.ChangeTrackingVersion): OfficeExtension.ClientResult<string>;
パラメーター
- changeTrackingVersion
- Word.ChangeTrackingVersion
省略可能。 値は 'Original' または 'Current' である必要があります。 既定値は 'Current' です。
戻り値
OfficeExtension.ClientResult<string>
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-change-tracking.yaml
// Gets the reviewed text.
await Word.run(async (context) => {
const range = context.document.getSelection();
const before = range.getReviewedText(Word.ChangeTrackingVersion.original);
const after = range.getReviewedText(Word.ChangeTrackingVersion.current);
await context.sync();
console.log("Reviewed text (before):", before.value, "Reviewed text (after):", after.value);
});
getReviewedText(changeTrackingVersionString)
ChangeTrackingVersion の選択に基づいて、レビューされたテキストを取得します。
getReviewedText(changeTrackingVersionString?: "Original" | "Current"): OfficeExtension.ClientResult<string>;
パラメーター
- changeTrackingVersionString
-
"Original" | "Current"
省略可能。 値は 'Original' または 'Current' である必要があります。 既定値は 'Current' です。
戻り値
OfficeExtension.ClientResult<string>
注釈
getTextRanges(endingMarks, trimSpacing)
句読点やその他の終了記号を使用して、範囲内のテキストの子範囲を取得します。
getTextRanges(endingMarks: string[], trimSpacing?: boolean): Word.RangeCollection;
パラメーター
- endingMarks
-
string[]
必須です。 句読点や他の終了記号を文字列の配列として指定します。
- trimSpacing
-
boolean
省略可能。 範囲コレクションで返される範囲の先頭と末尾から間隔文字 (スペース、タブ、列区切り、段落の終了記号) をトリミングするかどうかを示します。 既定値は false で、範囲の先頭と末尾の間隔文字が範囲コレクションに含まれることを示します。
戻り値
注釈
例
// 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);
}
});
getTrackedChanges()
範囲内の TrackedChange オブジェクトのコレクションを取得します。
getTrackedChanges(): Word.TrackedChangeCollection;
戻り値
注釈
insertBookmark(name)
範囲にブックマークを挿入します。 同じ名前のブックマークがどこかに存在する場合は、最初に削除されます。
insertBookmark(name: string): void;
パラメーター
- name
-
string
必須。 大文字と小文字を区別しないブックマーク名。 英数字とアンダースコア文字のみがサポートされています。 文字で始まる必要がありますが、ブックマークに非表示としてタグを付ける場合は、名前をアンダースコア文字で開始します。 名前は 40 文字以下にすることはできません。
戻り値
void
注釈
注: ブックマークを挿入する条件は、Word UI で行うのと似ています。 Word UI でのブックマークの管理の詳細については、「Word ドキュメントまたは Outlook メッセージでブックマークを追加または削除する」を参照してください。
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"
必須。 追加する中断の種類。
戻り値
void
注釈
例
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
// Queue a command to get the current selection and then
// create a proxy range object with the results.
const range = context.document.getSelection();
// Queue a command to insert a page break after the selected text.
range.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 selected text.');
});
insertComment(commentText)
範囲にコメントを挿入します。
insertComment(commentText: string): Word.Comment;
パラメーター
- commentText
-
string
必須。 挿入するコメント テキスト。
戻り値
comment オブジェクト
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-comments.yaml
// Sets a comment on the selected content.
await Word.run(async (context) => {
const text = $("#comment-text")
.val()
.toString();
const comment: Word.Comment = context.document.getSelection().insertComment(text);
// Load object to log in the console.
comment.load();
await context.sync();
console.log("Comment inserted:", comment);
});
insertContentControl(contentControlType)
Range オブジェクトをコンテンツ コントロールでラップします。
insertContentControl(contentControlType?: Word.ContentControlType.richText | Word.ContentControlType.plainText | Word.ContentControlType.checkBox | "RichText" | "PlainText" | "CheckBox"): Word.ContentControl;
パラメーター
省略可能。 挿入するコンテンツ コントロールの種類。 'RichText'、'PlainText'、または 'CheckBox' である必要があります。 既定値は "RichText" です。
戻り値
注釈
注: パラメーターは contentControlType
WordApi 1.5 で導入されました。 PlainText
WordApi 1.5 でサポートが追加されました。 CheckBox
WordApi 1.7 でサポートが追加されました。
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/90-scenarios/doc-assembly.yaml
// Simulates creation of a template. First searches the document for instances of the string "Contractor",
// then changes the format of each search result,
// then wraps each search result within a content control,
// finally sets a tag and title property on each content control.
await Word.run(async (context) => {
const results = context.document.body.search("Contractor");
results.load("font/bold");
// Check to make sure these content controls haven't been added yet.
const customerContentControls = context.document.contentControls.getByTag("customer");
customerContentControls.load("text");
await context.sync();
if (customerContentControls.items.length === 0) {
for (let i = 0; i < results.items.length; i++) {
results.items[i].font.bold = true;
let cc = results.items[i].insertContentControl();
cc.tag = "customer"; // This value is used in the next step of this sample.
cc.title = "Customer Name " + i;
}
}
await context.sync();
});
insertEndnote(insertText)
文末脚注を挿入します。 文末脚注の参照は、範囲の後に配置されます。
insertEndnote(insertText?: string): Word.NoteItem;
パラメーター
- insertText
-
string
省略可能。 文末脚注本文に挿入するテキスト。 既定値は "" です。
戻り値
注釈
insertField(insertLocation, fieldType, text, removeFormatting)
指定した場所にフィールドを挿入します。
insertField(insertLocation: Word.InsertLocation | "Replace" | "Start" | "End" | "Before" | "After", fieldType?: Word.FieldType, text?: string, removeFormatting?: boolean): Word.Field;
パラメーター
- insertLocation
-
Word.InsertLocation | "Replace" | "Start" | "End" | "Before" | "After"
必須。 フィールドが挿入される範囲を基準とした位置。 値は、'Replace'、'Start'、'End'、'Before'、または 'After' である必要があります。
- fieldType
- Word.FieldType
省略可能。 任意の FieldType 定数を指定できます。 既定値は、空です。
- text
-
string
省略可能。 指定したフィールド型に必要な場合は、追加のプロパティまたはオプション。
- removeFormatting
-
boolean
省略可能。 true
更新中 false
にフィールドに適用される書式を削除する場合は 。それ以外の場合は 。 既定値は です false
。
戻り値
注釈
重要:
Windows と Mac のWordでは、API では、Wordに記載されているすべての型の挿入と管理がサポートされています。Wordを除く FieldType。FieldType.others。
web 上のWordでは、API では、次のフィールド型の挿入と管理がサポートされています。
Word。FieldType.addin
Word。FieldType.date
Word。FieldType.hyperlink
Word。FieldType.toc
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-fields.yaml
// Inserts a Date field before selection.
await Word.run(async (context) => {
const range = context.document.getSelection().getRange();
const field = range.insertField(Word.InsertLocation.before, Word.FieldType.date, '\\@ "M/d/yyyy h:mm am/pm"', true);
field.load("result,code");
await context.sync();
if (field.isNullObject) {
console.log("There are no fields in this document.");
} else {
console.log("Code of the field: " + field.code, "Result of the field: " + JSON.stringify(field.result));
}
});
insertField(insertLocation, fieldTypeString, text, removeFormatting)
指定した場所にフィールドを挿入します。
insertField(insertLocation: Word.InsertLocation | "Replace" | "Start" | "End" | "Before" | "After", fieldTypeString?: "Addin" | "AddressBlock" | "Advance" | "Ask" | "Author" | "AutoText" | "AutoTextList" | "BarCode" | "Bibliography" | "BidiOutline" | "Citation" | "Comments" | "Compare" | "CreateDate" | "Data" | "Database" | "Date" | "DisplayBarcode" | "DocProperty" | "DocVariable" | "EditTime" | "Embedded" | "EQ" | "Expression" | "FileName" | "FileSize" | "FillIn" | "FormCheckbox" | "FormDropdown" | "FormText" | "GotoButton" | "GreetingLine" | "Hyperlink" | "If" | "Import" | "Include" | "IncludePicture" | "IncludeText" | "Index" | "Info" | "Keywords" | "LastSavedBy" | "Link" | "ListNum" | "MacroButton" | "MergeBarcode" | "MergeField" | "MergeRec" | "MergeSeq" | "Next" | "NextIf" | "NoteRef" | "NumChars" | "NumPages" | "NumWords" | "OCX" | "Page" | "PageRef" | "Print" | "PrintDate" | "Private" | "Quote" | "RD" | "Ref" | "RevNum" | "SaveDate" | "Section" | "SectionPages" | "Seq" | "Set" | "Shape" | "SkipIf" | "StyleRef" | "Subject" | "Subscriber" | "Symbol" | "TA" | "TC" | "Template" | "Time" | "Title" | "TOA" | "TOC" | "UserAddress" | "UserInitials" | "UserName" | "XE" | "Empty" | "Others" | "Undefined", text?: string, removeFormatting?: boolean): Word.Field;
パラメーター
- insertLocation
-
Word.InsertLocation | "Replace" | "Start" | "End" | "Before" | "After"
必須。 フィールドが挿入される範囲を基準とした位置。 値は、'Replace'、'Start'、'End'、'Before'、または 'After' である必要があります。
- fieldTypeString
-
"Addin" | "AddressBlock" | "Advance" | "Ask" | "Author" | "AutoText" | "AutoTextList" | "BarCode" | "Bibliography" | "BidiOutline" | "Citation" | "Comments" | "Compare" | "CreateDate" | "Data" | "Database" | "Date" | "DisplayBarcode" | "DocProperty" | "DocVariable" | "EditTime" | "Embedded" | "EQ" | "Expression" | "FileName" | "FileSize" | "FillIn" | "FormCheckbox" | "FormDropdown" | "FormText" | "GotoButton" | "GreetingLine" | "Hyperlink" | "If" | "Import" | "Include" | "IncludePicture" | "IncludeText" | "Index" | "Info" | "Keywords" | "LastSavedBy" | "Link" | "ListNum" | "MacroButton" | "MergeBarcode" | "MergeField" | "MergeRec" | "MergeSeq" | "Next" | "NextIf" | "NoteRef" | "NumChars" | "NumPages" | "NumWords" | "OCX" | "Page" | "PageRef" | "Print" | "PrintDate" | "Private" | "Quote" | "RD" | "Ref" | "RevNum" | "SaveDate" | "Section" | "SectionPages" | "Seq" | "Set" | "Shape" | "SkipIf" | "StyleRef" | "Subject" | "Subscriber" | "Symbol" | "TA" | "TC" | "Template" | "Time" | "Title" | "TOA" | "TOC" | "UserAddress" | "UserInitials" | "UserName" | "XE" | "Empty" | "Others" | "Undefined"
省略可能。 任意の FieldType 定数を指定できます。 既定値は、空です。
- text
-
string
省略可能。 指定したフィールド型に必要な場合は、追加のプロパティまたはオプション。
- removeFormatting
-
boolean
省略可能。 true
更新中 false
にフィールドに適用される書式を削除する場合は 。それ以外の場合は 。 既定値は です false
。
戻り値
注釈
重要:
Windows と Mac のWordでは、API では、Wordに記載されているすべての型の挿入と管理がサポートされています。Wordを除く FieldType。FieldType.others。
web 上のWordでは、API では、次のフィールド型の挿入と管理がサポートされています。
Word。FieldType.addin
Word。FieldType.date
Word。FieldType.hyperlink
Word。FieldType.toc
insertFileFromBase64(base64File, insertLocation)
指定した位置に文書を挿入します。
insertFileFromBase64(base64File: string, insertLocation: Word.InsertLocation | "Replace" | "Start" | "End" | "Before" | "After"): Word.Range;
パラメーター
- base64File
-
string
必須です。 .docx ファイルの Base64 でエンコードされたコンテンツ。
- insertLocation
-
Word.InsertLocation | "Replace" | "Start" | "End" | "Before" | "After"
必須です。 値は、'Replace'、'Start'、'End'、'Before'、または 'After' である必要があります。
戻り値
注釈
注: 挿入するドキュメントに ActiveX コントロールが含まれている場合 (フォーム フィールドの可能性があります)、挿入はサポートされません。 このようなフォーム フィールドを、シナリオに適したコンテンツ コントロールまたはその他のオプションに置き換えることを検討してください。
例
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
// Queue a command to get the current selection and then
// create a proxy range object with the results.
const range = context.document.getSelection();
// Queue a command to insert base64 encoded .docx at the beginning of the range.
// You'll need to implement getBase64() to make this work.
range.insertFileFromBase64(getBase64(), Word.InsertLocation.start);
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
await context.sync();
console.log('Added base64 encoded text to the beginning of the range.');
});
insertFootnote(insertText)
脚注を挿入します。 脚注の参照は、範囲の後に配置されます。
insertFootnote(insertText?: string): Word.NoteItem;
パラメーター
- insertText
-
string
省略可能。 脚注本文に挿入するテキスト。 既定値は "" です。
戻り値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-footnotes.yaml
// Sets a footnote on the selected content.
await Word.run(async (context) => {
const text = $("#input-footnote")
.val()
.toString();
const footnote = context.document.getSelection().insertFootnote(text);
await context.sync();
console.log("Inserted footnote.");
});
insertHtml(html, insertLocation)
指定した位置に HTML を挿入します。
insertHtml(html: string, insertLocation: Word.InsertLocation | "Replace" | "Start" | "End" | "Before" | "After"): Word.Range;
パラメーター
- html
-
string
必須です。 挿入する HTML。
- insertLocation
-
Word.InsertLocation | "Replace" | "Start" | "End" | "Before" | "After"
必須。 値は、'Replace'、'Start'、'End'、'Before'、または 'After' である必要があります。
戻り値
注釈
例
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
// Queue a command to get the current selection and then
// create a proxy range object with the results.
const range = context.document.getSelection();
// Queue a command to insert HTML in to the beginning of the range.
range.insertHtml('<strong>This is text inserted with range.insertHtml()</strong>', Word.InsertLocation.start);
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
await context.sync();
console.log('HTML added to the beginning of the range.');
});
insertInlinePictureFromBase64(base64EncodedImage, insertLocation)
指定された位置に画像を挿入します。
insertInlinePictureFromBase64(base64EncodedImage: string, insertLocation: Word.InsertLocation | "Replace" | "Start" | "End" | "Before" | "After"): Word.InlinePicture;
パラメーター
- base64EncodedImage
-
string
必須です。 挿入する Base64 でエンコードされたイメージ。
- insertLocation
-
Word.InsertLocation | "Replace" | "Start" | "End" | "Before" | "After"
必須。 値は、'Replace'、'Start'、'End'、'Before'、または 'After' である必要があります。
戻り値
注釈
insertOoxml(ooxml, insertLocation)
指定した位置に OOXML を挿入します。
insertOoxml(ooxml: string, insertLocation: Word.InsertLocation | "Replace" | "Start" | "End" | "Before" | "After"): Word.Range;
パラメーター
- ooxml
-
string
必須。 挿入する OOXML を指定します。
- insertLocation
-
Word.InsertLocation | "Replace" | "Start" | "End" | "Before" | "After"
必須。 値は、'Replace'、'Start'、'End'、'Before'、または 'After' である必要があります。
戻り値
注釈
例
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
// Queue a command to get the current selection and then
// create a proxy range object with the results.
const range = context.document.getSelection();
// Queue a command to insert OOXML in to the beginning of the range.
range.insertOoxml("<pkg:package xmlns:pkg='http://schemas.microsoft.com/office/2006/xmlPackage'><pkg:part pkg:name='/_rels/.rels' pkg:contentType='application/vnd.openxmlformats-package.relationships+xml' pkg:padding='512'><pkg:xmlData><Relationships xmlns='http://schemas.openxmlformats.org/package/2006/relationships'><Relationship Id='rId1' Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument' Target='word/document.xml'/></Relationships></pkg:xmlData></pkg:part><pkg:part pkg:name='/word/document.xml' pkg:contentType='application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml'><pkg:xmlData><w:document xmlns:w='http://schemas.openxmlformats.org/wordprocessingml/2006/main' ><w:body><w:p><w:pPr><w:spacing w:before='360' w:after='0' w:line='480' w:lineRule='auto'/><w:rPr><w:color w:val='70AD47' w:themeColor='accent6'/><w:sz w:val='28'/></w:rPr></w:pPr><w:r><w:rPr><w:color w:val='70AD47' w:themeColor='accent6'/><w:sz w:val='28'/></w:rPr><w:t>This text has formatting directly applied to achieve its font size, color, line spacing, and paragraph spacing.</w:t></w:r></w:p></w:body></w:document></pkg:xmlData></pkg:part></pkg:package>", Word.InsertLocation.start);
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
await context.sync();
console.log('OOXML added to the beginning of the range.');
});
// Read "Create better add-ins for Word with Office Open XML" for guidance on working with OOXML.
// https://learn.microsoft.com/office/dev/add-ins/word/create-better-add-ins-for-word-with-office-open-xml
insertParagraph(paragraphText, insertLocation)
指定した位置に、段落を挿入します。
insertParagraph(paragraphText: string, insertLocation: Word.InsertLocation.before | Word.InsertLocation.after | "Before" | "After"): Word.Paragraph;
パラメーター
- paragraphText
-
string
必須。 挿入する段落テキスト。
戻り値
注釈
例
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
// Queue a command to get the current selection and then
// create a proxy range object with the results.
const range = context.document.getSelection();
// Queue a command to insert the paragraph after the range.
range.insertParagraph('Content of a new paragraph', 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('Paragraph added to the end of the range.');
});
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
必須。 表の列数。
- values
-
string[][]
省略可能な 2 次元配列。 対応する文字列が配列で指定されている場合、セルに設定されます。
戻り値
注釈
insertText(text, insertLocation)
指定した位置にテキストを挿入します。
insertText(text: string, insertLocation: Word.InsertLocation | "Replace" | "Start" | "End" | "Before" | "After"): Word.Range;
パラメーター
- text
-
string
必須。 挿入するテキスト。
- insertLocation
-
Word.InsertLocation | "Replace" | "Start" | "End" | "Before" | "After"
必須。 値は、'Replace'、'Start'、'End'、'Before'、または 'After' である必要があります。
戻り値
注釈
例
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
// Queue a command to get the current selection and then
// create a proxy range object with the results.
const range = context.document.getSelection();
// Queue a command to insert the paragraph at the end of the range.
range.insertText('New text inserted into the range.', 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('Text added to the end of the range.');
});
intersectWith(range)
別の範囲とこの範囲の交点として、新しい範囲を返します。 この範囲は変更されません。 ItemNotFound
2 つの範囲が重複または隣接していない場合は、エラーをスローします。
intersectWith(range: Word.Range): Word.Range;
パラメーター
- range
- Word.Range
必須。 別の範囲。
戻り値
注釈
intersectWithOrNullObject(range)
別の範囲とこの範囲の交点として、新しい範囲を返します。 この範囲は変更されません。 2 つの範囲が重複または隣接していない場合、このメソッドは プロパティが に設定されたオブジェクトをisNullObject
true
返します。 詳細については、「 *OrNullObject メソッドとプロパティ」を参照してください。
intersectWithOrNullObject(range: Word.Range): Word.Range;
パラメーター
- range
- Word.Range
必須です。 別の範囲。
戻り値
注釈
load(options)
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync()
を呼び出す必要があります。
load(options?: Word.Interfaces.RangeLoadOptions): Word.Range;
パラメーター
- options
- Word.Interfaces.RangeLoadOptions
読み込むオブジェクトのプロパティのオプションを提供します。
戻り値
load(propertyNames)
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync()
を呼び出す必要があります。
load(propertyNames?: string | string[]): Word.Range;
パラメーター
- propertyNames
-
string | string[]
読み込むプロパティを指定するコンマ区切り文字列または文字列の配列。
戻り値
load(propertyNamesAndPaths)
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync()
を呼び出す必要があります。
load(propertyNamesAndPaths?: {
select?: string;
expand?: string;
}): Word.Range;
パラメーター
- 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; }
省略可能。 検索のオプション。
戻り値
注釈
select(selectionMode)
範囲を選択して、その範囲に Word の UI を移動します。
select(selectionMode?: Word.SelectionMode): void;
パラメーター
- selectionMode
- Word.SelectionMode
省略可能。 選択モードは、'Select'、'Start'、または 'End' である必要があります。 'Select' が既定値です。
戻り値
void
注釈
例
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
// Queue a command to get the current selection and then
// create a proxy range object with the results.
const range = context.document.getSelection();
// Queue a command to insert HTML in to the beginning of the range.
range.insertHtml('<strong>This is text inserted with range.insertHtml()</strong>', Word.InsertLocation.start);
// Queue a command to select the HTML that was inserted.
range.select();
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
await context.sync();
console.log('Selected the range.');
});
select(selectionModeString)
範囲を選択して、その範囲に Word の UI を移動します。
select(selectionModeString?: "Select" | "Start" | "End"): void;
パラメーター
- selectionModeString
-
"Select" | "Start" | "End"
省略可能。 選択モードは、'Select'、'Start'、または 'End' である必要があります。 'Select' が既定値です。
戻り値
void
注釈
set(properties, options)
オブジェクトの複数のプロパティを同時に設定します。 適切なプロパティを持つプレーン オブジェクトまたは同じ型の別の API オブジェクトを渡すことができます。
set(properties: Interfaces.RangeUpdateData, options?: OfficeExtension.UpdateOptions): void;
パラメーター
- properties
- Word.Interfaces.RangeUpdateData
メソッドが呼び出されるオブジェクトのプロパティに等形的に構造化されたプロパティを持つ JavaScript オブジェクト。
- options
- OfficeExtension.UpdateOptions
properties オブジェクトが読み取り専用プロパティを設定しようとした場合にエラーを抑制するオプションを提供します。
戻り値
void
set(properties)
既存の読み込まれたオブジェクトに基づいて、オブジェクトに複数のプロパティを同時に設定します。
set(properties: Word.Range): void;
パラメーター
- properties
- Word.Range
戻り値
void
split(delimiters, multiParagraphs, trimDelimiters, trimSpacing)
区切り記号を使用して、範囲を子の範囲に分割します。
split(delimiters: string[], multiParagraphs?: boolean, trimDelimiters?: boolean, trimSpacing?: boolean): Word.RangeCollection;
パラメーター
- delimiters
-
string[]
必須です。 文字列の配列としての区切り記号。
- multiParagraphs
-
boolean
省略可能。 返された子範囲が複数の段落をカバーできるかどうかを示します。 既定値は false で、段落の境界が区切り記号としても使用されることを示します。
- trimDelimiters
-
boolean
省略可能。 範囲コレクション内の範囲から区切り記号をトリミングするかどうかを示します。 既定値は false で、範囲コレクションで返される範囲に区切り記号が含まれていることを示します。
- trimSpacing
-
boolean
省略可能。 範囲コレクションで返される範囲の先頭と末尾から間隔文字 (スペース、タブ、列区切り、段落の終了記号) をトリミングするかどうかを示します。 既定値は false で、範囲の先頭と末尾の間隔文字が範囲コレクションに含まれることを示します。
戻り値
注釈
toJSON()
API オブジェクトが に渡されたときにより便利な出力を提供するために、JavaScript toJSON()
メソッドを JSON.stringify()
オーバーライドします。 (JSON.stringify
さらに、渡される オブジェクトの メソッドを呼び出toJSON
します)。一方、元のWord。Range オブジェクトは API オブジェクトです。このメソッドは、元のtoJSON
オブジェクトから読み込まれた子プロパティの浅いコピーを含むプレーンな JavaScript オブジェクト (としてWord.Interfaces.RangeData
型指定) を返します。
toJSON(): Word.Interfaces.RangeData;
戻り値
track()
ドキュメントの環境変更に基づいて自動的に調整する目的でオブジェクトを追跡します。 この呼び出しは、context.trackedObjects.add(thisObject)の短縮形です。 このオブジェクトを呼び出しで .sync
使用していて、".run" バッチのシーケンシャル実行の外部で使用していて、プロパティを設定するとき、またはオブジェクトのメソッドを呼び出すときに "InvalidObjectPath" エラーが発生する場合は、オブジェクトが最初に作成されたときに追跡対象のオブジェクト コレクションにオブジェクトを追加する必要があります。 このオブジェクトがコレクションの一部である場合は、親コレクションも追跡する必要があります。
track(): Word.Range;
戻り値
untrack()
前に追跡されていた場合、このオブジェクトに関連付けられているメモリを解放します。 この呼び出しは、context.trackedObjects.remove(thisObject)の短縮形です。 追跡対象オブジェクトが多いとホスト アプリケーションの動作が遅くなります。追加したオブジェクトが不要になったら、必ずそれを解放してください。 メモリ解放が有効になる前に を呼び出す context.sync()
必要があります。
untrack(): Word.Range;
戻り値
Office Add-ins
フィードバック
https://aka.ms/ContentUserFeedback」を参照してください。
以下は間もなく提供いたします。2024 年を通じて、コンテンツのフィードバック メカニズムとして GitHub の issue を段階的に廃止し、新しいフィードバック システムに置き換えます。 詳細については、「フィードバックの送信と表示