Word.Range class
文書内の連続した領域を表します。
- Extends
注釈
使用元
- Word.本文: getRange、insertFileFromBase64、insertHtml、insertOoxml、insertText
- Word.ブックマーク: 範囲
- Word.BookmarkCollection: add
- Word.中断:範囲
- Word.BuildingBlock: 挿入
- Word.BuildingBlockCollection: add
- Word.BuildingBlockEntryCollection: add
- Word.BuildingBlockGalleryContentControl: 範囲
- Word.CoauthoringLock: 範囲
- Word.CoauthoringLockAddOptions: 範囲
- Word.CoauthoringUpdate: 範囲
- Word.コメント: getRange
- Word.競合:範囲
- Word.ContentControl: getRange、insertFileFromBase64、insertHtml、insertOoxml、insertText
- Word.ContentControlPlaceholderOptions: 範囲
- Word.CritiqueAnnotation: 範囲
- Word.DatePickerContentControl: 範囲
- Word.ドキュメント: content、getBookmarkRange、getBookmarkRangeOrNullObject、getRange、getSelection、goTo
- Word.DocumentCreated: getBookmarkRange、getBookmarkRangeOrNullObject
- Word.エディター: nextRange, range
- Word.フィールド: result
- Word.フレーム: 範囲
- Word.FrameCollection: add
- Word.GroupContentControl: 範囲
- Word.HtmlDivision: 範囲
- Word.ハイパーリンク: 範囲
- Word.HyperlinkCollection: add
- Word.インデックス: 範囲
- Word.IndexCollection: add, markAllEntries
- Word.InlinePicture: getRange、insertFileFromBase64、insertHtml、insertOoxml、insertText
- Word.注:参照
- Word.ページ: getRange
- Word.段落: getRange、insertFileFromBase64、insertHtml、insertOoxml、insertText
- Word.ParagraphCollection: add
- Word.PictureContentControl: 範囲
- Word.RangeCollection: getFirst、getFirstOrNullObject、items
- Word.RangeScopedCollection: getItem, items
- Word.RepeatingSectionContentControl: 範囲
- Word.RepeatingSectionItem: 範囲
- Word.改訂: movedRange、範囲
- Word.選択: formattedText、getNextRange、getPreviousRange、goTo、goToNext、goToPrevious、isEqual、isInRange、isInStory、範囲
- Word.テーブル: convertToText、getRange
- Word.TableOfAuthorities: 範囲
- Word.TableOfAuthoritiesCollection: add, markCitation
- Word.目次: 範囲
- Word.TableOfContentsCollection: add, markTocEntry
- Word.TableOfFigures: 範囲
- Word.TableOfFiguresCollection: add, markTocEntry
- Word.TableRow: convertToText, range
- Word.TableRowCollection: convertToText
- Word.TrackedChange: getRange
- Word.表示: collapseOutline、expandOutline
- Word.XmlNode: 範囲
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/basic-range-operations.yaml
// Reads the text and checks whether the first paragraph range is empty.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange();
paragraphRange.load("text,isEmpty,style");
await context.sync();
console.log("First paragraph's properties:", { text: paragraphRange.text, isEmpty: paragraphRange.isEmpty, style: paragraphRange.style });
});
プロパティ
| bold | 範囲を太字として書式設定するかどうかを指定します。 |
| bold |
右から左の言語ドキュメントで、範囲を太字として書式設定するかどうかを指定します。 |
| bookmarks | 範囲内のすべてのブックマークを表す |
| borders | 範囲のすべての境界線を表す |
| case | 範囲内のテキストの大文字と小文字を表す |
| character |
範囲の文字幅を指定します。 |
| combine |
範囲に結合文字が含まれているかどうかを指定します。 |
| conflicts | すべてのWordを含む |
| content |
範囲内の |
| context | オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。 |
| disable |
対応する |
| editors | ドキュメントが保護 (読み取り専用) モードのときに範囲の変更を承認されているすべてのユーザーを表す |
| emphasis |
文字または指定した文字列の強調記号を指定します。 |
| end | 範囲の文字の終了位置を指定します。 |
| endnotes | 範囲内の文末脚注のコレクションを取得します。 |
| fields | 範囲内の |
| fit |
Microsoft Word が現在の選択範囲または範囲にテキストを収める幅 (現在の測定単位) を指定します。 |
| font | 範囲のテキスト形式を取得します。 これを使用して、フォント名、サイズ、色、およびその他のプロパティを取得および設定します。 |
| footnotes | 範囲内の脚注のコレクションを取得します。 |
| frames | 範囲内のすべてのフレームを表す |
| grammar |
範囲またはドキュメントに対して文法チェックが実行されたかどうかを指定します。 |
| has |
範囲の校正の状態 (スペル チェックと文法チェック) を指定します。 |
| highlight |
範囲のハイライト カラーを指定します。 |
| horizontal |
縦書きテキスト内に設定された横書きテキストの書式設定を指定します。 |
| hyperlink | 範囲内の最初のハイパーリンクを取得するか、または範囲にハイパーリンクを設定します。 範囲に新しいハイパーリンクを設定すると、範囲内のすべてのハイパーリンクが削除されます。 住所の部分とオプションの場所の部分を区切るには、'#' を使用します。 |
| hyperlinks | 範囲内のすべてのハイパーリンクを表す |
| id | 範囲の ID を指定します。 |
| inline |
範囲内の |
| is |
範囲の長さが 0 であるかどうかを確認します。 |
| is |
範囲が折りたたまれていて、テーブルの行末のマークにあるかどうかを取得します。 |
| is |
範囲内のテキストが画面に表示されているかどうかを取得します。 |
| italic | フォントまたは範囲を斜体として書式設定するかどうかを指定します。 |
| italic |
フォントまたは範囲を斜体 (右から左の言語) として書式設定するかどうかを指定します。 |
| kana | 日本語のテキストの範囲がひらがなかカタカナかを指定します。 |
| language |
Microsoft Word が範囲内のテキストの言語を検出したかどうかを指定します。 |
| language |
範囲の言語を表す |
| language |
範囲の東アジア言語を指定します。 |
| language |
東アジア言語として分類されていない範囲の言語を指定します。 |
| list |
範囲のリストの書式設定上のすべての特性を表す |
| lists | 範囲内の |
| pages | 範囲内のページのコレクションを取得します。 |
| paragraphs | 範囲内の |
| parent |
範囲の親の本文を取得します。 |
| parent |
範囲を含む、現在サポートされているコンテンツ コントロールを取得します。 親コンテンツ コントロールがない場合は |
| parent |
範囲を含む、現在サポートされているコンテンツ コントロールを取得します。 親コンテンツ コントロールがない場合、このメソッドは、 |
| parent |
範囲を含むテーブルを取得します。 テーブルに含まれない場合は、 |
| parent |
範囲を含むテーブルのセルを取得します。 テーブル セルに含まれない場合は、 |
| parent |
範囲を含むテーブルのセルを取得します。 テーブルのセルに含まれない場合、このメソッドは、 |
| parent |
範囲を含むテーブルを取得します。 テーブルに含まれない場合、このメソッドは |
| revisions | 範囲内の変更履歴を表すリビジョンのコレクションを取得します。 |
| sections | 範囲内のセクションのコレクションを取得します。 |
| shading | 範囲の網掛け書式を参照する |
| shapes | 範囲に固定されている |
| show |
印刷されない文字 (隠しテキスト、タブ記号、スペース記号、段落記号など) をすべて表示するかどうかを指定します。 |
| spelling |
範囲またはドキュメント全体でスペル チェックが行われるかどうかを指定します。 |
| start | 範囲の開始文字位置を指定します。 |
| story |
範囲を含むストーリー内のキャラクターの数を取得します。 |
| story |
範囲のストーリー タイプを取得します。 |
| style | 範囲のスタイル名を指定します。 カスタム スタイルとローカライズされたスタイルの名前には、このプロパティを使用します。 ロケール間で移植可能な組み込みスタイルを使用するには、"styleBuiltIn" プロパティを参照してください。 |
| style |
範囲の組み込みスタイル名を指定します。 ロケール間で移植可能な組み込みスタイルの場合は、このプロパティを使用します。 カスタム スタイルまたはローカライズされたスタイルの名前を使用するには、"style" プロパティを参照してください。 |
| table |
範囲内のすべてのテーブル列を表す |
| tables | 範囲内の |
| text | 範囲のテキストを取得します。 |
| two |
Microsoft Word が 2 行のテキストを 1 つに設定するかどうか、およびテキストを囲む文字を指定する (存在する場合)。 |
| underline | 範囲に適用される下線の種類を指定します。 |
メソッド
| clear() |
|
| compare |
この範囲の場所を別の範囲の場所と比較します。 |
| delete() | 文書から範囲と、その範囲の内容を削除します。 |
| detect |
範囲テキストを分析して、記述されている言語を決定します。 |
| expand |
別の範囲を対象にするために、いずれかの方向でこの範囲から拡張する新しい範囲を返します。 この範囲は変更されません。 2 つの範囲に和集合がない場合は、 |
| expand |
別の範囲を対象にするために、いずれかの方向でこの範囲から拡張する新しい範囲を返します。 この範囲は変更されません。 2 つの範囲に和集合がない場合、このメソッドは |
| get |
範囲内または範囲内に重なるすべてのブックマークの名前を取得します。 ブックマークは、名前がアンダースコア文字で始まる場合、非表示になります。 |
| get |
範囲に関連付けられているコメントを取得します。 |
| get |
範囲内の現在サポートされているコンテンツ コントロールを取得します。 |
| get |
|
| get |
範囲内のハイパーリンクの子の範囲を取得します。 |
| get |
句読点やその他の終了記号を使用して、次のテキスト範囲を取得します。 このテキスト範囲が最後のテキスト範囲である場合は、 |
| get |
句読点やその他の終了記号を使用して、次のテキスト範囲を取得します。 このテキスト範囲が最後のテキスト範囲である場合、このメソッドは、 |
| get |
|
| get |
|
| get |
ChangeTrackingVersion の選択に基づいてレビューされたテキストを取得します。 |
| get |
ChangeTrackingVersion の選択に基づいてレビューされたテキストを取得します。 |
| get |
句読点やその他の終了記号を使用して、範囲内のテキストの子範囲を取得します。 |
| get |
範囲内の |
| highlight() | ドキュメントの内容を変更せずに範囲を一時的に強調表示します。 テキストを永続的に強調表示するには、範囲の |
| insert |
範囲にブックマークを挿入します。 同じ名前のブックマークがどこかに存在する場合は、最初に削除されます。 |
| insert |
メイン文書の指定した位置に、区切りを挿入します。 |
| insert |
テキストの前にフローティング キャンバスを挿入し、アンカーを範囲の先頭に配置します。 |
| insert |
範囲にコメントを挿入する。 |
| insert |
|
| insert |
文末脚注を挿入します。 文末脚注の参照は範囲の後に配置されます。 |
| insert |
指定した場所にフィールドを挿入します。 |
| insert |
指定した場所にフィールドを挿入します。 |
| insert |
指定した位置に文書を挿入します。 挿入する文書の最大サイズは 4 MB です。 |
| insert |
脚注を挿入します。 脚注参照は、範囲の後に配置されます。 |
| insert |
テキストの前に幾何学図形を挿入し、範囲の先頭にアンカーを配置します。 |
| insert |
テキストの前に幾何学図形を挿入し、範囲の先頭にアンカーを配置します。 |
| insert |
指定した位置に HTML を挿入します。 |
| insert |
指定された位置に画像を挿入します。 |
| insert |
指定した位置に OOXML を挿入します。 |
| insert |
指定した位置に、段落を挿入します。 |
| insert |
テキストの前に浮動ピクチャを挿入し、範囲の先頭にアンカーを配置します。 |
| insert |
指定した数の行と列を含むテーブルを挿入します。 |
| insert |
指定した位置にテキストを挿入します。 |
| insert |
テキストの前にフローティング テキスト ボックスを挿入し、アンカーを範囲の先頭に配置します。 |
| intersect |
別の範囲とこの範囲の交点として、新しい範囲を返します。 この範囲は変更されません。 2 つの範囲が重なっていない、または隣接していない場合は、 |
| intersect |
別の範囲とこの範囲の交点として、新しい範囲を返します。 この範囲は変更されません。 2 つの範囲が重複または隣接していない場合、このメソッドは |
| load(options) | オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、 |
| load(property |
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、 |
| load(property |
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、 |
| remove |
|
| search(search |
|
| select(selection |
範囲を選択して、その範囲に Word の UI を移動します。 |
| select(selection |
範囲を選択して、その範囲に Word の UI を移動します。 |
| set(properties, options) | オブジェクトの複数のプロパティを同時に設定します。 適切なプロパティを持つプレーン オブジェクト、または同じ型の別の API オブジェクトを渡すことができます。 |
| set(properties) | 既存の読み込まれたオブジェクトに基づいて、オブジェクトに複数のプロパティを同時に設定します。 |
| split(delimiters, multi |
区切り記号を使用して、範囲を子の範囲に分割します。 |
| toJSON() | API オブジェクトが |
| track() | ドキュメントの環境変更に基づいて自動的に調整する目的でオブジェクトを追跡します。 この呼び出しは、 context.trackedObjects.add(thisObject) の短縮形です。 このオブジェクトを |
| untrack() | 前に追跡されていた場合、このオブジェクトに関連付けられているメモリを解放します。 この呼び出しは、 context.trackedObjects.remove(thisObject) の省略形です。 追跡対象オブジェクトが多いとホスト アプリケーションの動作が遅くなります。追加したオブジェクトが不要になったら、必ずそれを解放してください。 メモリ リリースを有効にする前に、 |
イベント
| on |
新しいコメントが追加されたときに発生します。 |
| on |
コメントまたはその応答が変更されたときに発生します。 |
| on |
コメントの選択が解除されたときに発生します。 |
| on |
コメントが選択されているときに発生します。 |
プロパティの詳細
bold
範囲を太字として書式設定するかどうかを指定します。
readonly bold: boolean;
プロパティ値
boolean
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/28-formatting/character-formatting-and-case-desktop.yaml
// Reads character formatting on the first paragraph.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange(Word.RangeLocation.content);
paragraphRange.load("text,bold,italic,boldBidirectional,italicBidirectional,case,highlightColorIndex");
await context.sync();
console.log("First paragraph's formatting:", {
text: paragraphRange.text,
bold: paragraphRange.bold,
italic: paragraphRange.italic,
boldBidirectional: paragraphRange.boldBidirectional,
italicBidirectional: paragraphRange.italicBidirectional,
case: paragraphRange.case,
highlightColorIndex: paragraphRange.highlightColorIndex
});
});
boldBidirectional
右から左の言語ドキュメントで、範囲を太字として書式設定するかどうかを指定します。
readonly boldBidirectional: boolean;
プロパティ値
boolean
注釈
bookmarks
範囲内のすべてのブックマークを表す BookmarkCollection オブジェクトを返します。
readonly bookmarks: Word.BookmarkCollection;
プロパティ値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/manage-range-bookmarks.yaml
// Read bookmark properties and the text enclosed by each bookmark.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange();
const bookmarks: Word.BookmarkCollection = paragraphRange.bookmarks;
bookmarks.load("items/name,items/start,items/end,items/isEmpty,items/isColumn,items/storyType,items/range/text");
await context.sync();
console.log(`Bookmarks found: ${bookmarks.items.length}`);
bookmarks.items.forEach((bookmark: Word.Bookmark) => {
console.log("Bookmark details:", {
name: bookmark.name,
start: bookmark.start,
end: bookmark.end,
isEmpty: bookmark.isEmpty,
isColumn: bookmark.isColumn,
storyType: bookmark.storyType,
text: bookmark.range.text
});
});
});
borders
範囲のすべての境界線を表す BorderUniversalCollection オブジェクトを返します。
readonly borders: Word.BorderUniversalCollection;
プロパティ値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/28-formatting/range-borders-and-shading-desktop.yaml
// Reads the border formatting of the first paragraph's text.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange(Word.RangeLocation.content);
const borders: Word.BorderUniversalCollection = paragraphRange.borders;
borders.load("items/color,items/lineStyle,items/lineWidth,items/isVisible");
await context.sync();
console.log("First paragraph's border formatting:");
borders.items.forEach((border: Word.BorderUniversal) => {
console.log("Border:", {
color: border.color,
lineStyle: border.lineStyle,
lineWidth: border.lineWidth,
isVisible: border.isVisible
});
});
});
case
範囲内のテキストの大文字と小文字を表す CharacterCase 値を指定します。
case: Word.CharacterCase | "Next" | "Lower" | "Upper" | "TitleWord" | "TitleSentence" | "Toggle" | "HalfWidth" | "FullWidth" | "Katakana" | "Hiragana";
プロパティ値
Word.CharacterCase | "Next" | "Lower" | "Upper" | "TitleWord" | "TitleSentence" | "Toggle" | "HalfWidth" | "FullWidth" | "Katakana" | "Hiragana"
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/28-formatting/character-formatting-and-case-desktop.yaml
// Converts the first paragraph's text to uppercase.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange(Word.RangeLocation.content);
const characterCase: Word.CharacterCase = Word.CharacterCase.upper;
paragraphRange.case = characterCase;
await context.sync();
console.log("Converted the first paragraph's text to uppercase.");
});
characterWidth
範囲の文字幅を指定します。
characterWidth: Word.CharacterWidth | "Half" | "Full";
プロパティ値
Word.CharacterWidth | "Half" | "Full"
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/28-formatting/apply-character-layout-desktop.yaml
// Converts the first paragraph's Latin characters and digits to full width.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange(Word.RangeLocation.content);
const characterWidth: Word.CharacterWidth = Word.CharacterWidth.full;
paragraphRange.characterWidth = characterWidth;
await context.sync();
console.log("Converted the first paragraph's Latin characters and digits to full width.");
});
combineCharacters
範囲に結合文字が含まれているかどうかを指定します。
combineCharacters: boolean;
プロパティ値
boolean
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/28-formatting/apply-character-layout-desktop.yaml
// Combines the first paragraph's short group of characters.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange(Word.RangeLocation.content);
paragraphRange.combineCharacters = true;
await context.sync();
console.log("Enabled combined characters on the first paragraph. Get layout settings to inspect the flag.");
});
conflicts
すべてのWordを含む ConflictCollection オブジェクトを返します。範囲内の競合オブジェクト。
readonly conflicts: Word.ConflictCollection;
プロパティ値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/05-coauthoring/manage-coauthoring-conflicts.yaml
// Gets coauthoring conflicts associated with the selected range.
await Word.run(async (context) => {
const selectedRange: Word.Range = context.document.getSelection();
const conflicts: Word.ConflictCollection = selectedRange.conflicts;
conflicts.load("items/type");
await context.sync();
console.log(`Conflicts in the selection: ${conflicts.items.length}`);
conflicts.items.forEach((conflict: Word.Conflict) => console.log(`Conflict type: ${conflict.type}`));
});
contentControls
範囲内の ContentControl オブジェクトのコレクションを取得します。
readonly contentControls: Word.ContentControlCollection;
プロパティ値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/inspect-range-structure.yaml
// Gets the content controls contained in the document body range.
await Word.run(async (context) => {
const bodyRange: Word.Range = context.document.body.getRange();
const contentControls: Word.ContentControlCollection = bodyRange.contentControls;
contentControls.load("items/tag,items/title,items/text");
await context.sync();
console.log(`Content controls found: ${contentControls.items.length}`);
contentControls.items.forEach((control: Word.ContentControl) => {
console.log({ tag: control.tag, title: control.title, text: control.text });
});
});
context
オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。
context: RequestContext;
プロパティ値
disableCharacterSpaceGrid
対応する Range オブジェクトの 1 行あたりの文字数を Microsoft Word で無視するかどうかを指定します。
readonly disableCharacterSpaceGrid: boolean;
プロパティ値
boolean
注釈
editors
ドキュメントが保護 (読み取り専用) モードのときに範囲の変更を承認されているすべてのユーザーを表す EditorCollection オブジェクトを返します。
readonly editors: Word.EditorCollection;
プロパティ値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/manage-range-editing-permissions-desktop.yaml
// Reads editing-permission entries for the first paragraph range.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange(Word.RangeLocation.content);
const editors: Word.EditorCollection = paragraphRange.editors;
const editorCount: OfficeExtension.ClientResult<number> = editors.getCount();
await context.sync();
const editorEntries: Word.Editor[] = [];
for (let index = 0; index < editorCount.value; index++) {
const editor: Word.Editor = editors.getItemAt(index);
editor.load("name,id");
editorEntries.push(editor);
}
await context.sync();
console.log(`Editing-permission entries: ${editorCount.value}`);
editorEntries.forEach((editor: Word.Editor) => console.log({ name: editor.name, id: editor.id }));
});
emphasisMark
文字または指定した文字列の強調記号を指定します。
readonly emphasisMark: Word.EmphasisMark | "None" | "OverSolidCircle" | "OverComma" | "OverWhiteCircle" | "UnderSolidCircle";
プロパティ値
Word.EmphasisMark | "None" | "OverSolidCircle" | "OverComma" | "OverWhiteCircle" | "UnderSolidCircle"
注釈
end
範囲の文字の終了位置を指定します。
end: number;
プロパティ値
number
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/inspect-and-adjust-range-boundaries-desktop.yaml
// Selects the first paragraph's text except its last character.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange(Word.RangeLocation.content);
paragraphRange.load("start,end");
await context.sync();
if (paragraphRange.start === paragraphRange.end) {
console.warn("The paragraph is empty. Run Set up again.");
return;
}
paragraphRange.end = paragraphRange.end - 1;
paragraphRange.select();
await context.sync();
console.log("Selected the range with its ending position reduced by one character.");
});
endnotes
範囲内の文末脚注のコレクションを取得します。
readonly endnotes: Word.NoteItemCollection;
プロパティ値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-footnotes.yaml
// Gets the text of every endnote in the document body range.
await Word.run(async (context) => {
const bodyRange: Word.Range = context.document.body.getRange();
const endnotes: Word.NoteItemCollection = bodyRange.endnotes;
endnotes.load("items/body/text");
await context.sync();
console.log(`Endnotes found: ${endnotes.items.length}`);
endnotes.items.forEach((endnote: Word.NoteItem) => console.log(endnote.body.text));
});
fields
範囲内の Field オブジェクトのコレクションを取得します。
readonly fields: Word.FieldCollection;
プロパティ値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/inspect-range-structure.yaml
// Gets field codes and displayed results in the document body range.
await Word.run(async (context) => {
const bodyRange: Word.Range = context.document.body.getRange();
const fields: Word.FieldCollection = bodyRange.fields;
fields.load("items/code,items/result/text");
await context.sync();
console.log(`Fields found: ${fields.items.length}`);
fields.items.forEach((field: Word.Field) => console.log({ code: field.code, text: field.result.text }));
});
fitTextWidth
Microsoft Word が現在の選択範囲または範囲にテキストを収める幅 (現在の測定単位) を指定します。
fitTextWidth: number;
プロパティ値
number
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/28-formatting/apply-character-layout-desktop.yaml
// Fits the first paragraph's text into a specified width.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange(Word.RangeLocation.content);
paragraphRange.fitTextWidth = 100;
await context.sync();
console.log("Fitted the first paragraph's text into 100 current measurement units.");
});
font
範囲のテキスト形式を取得します。 これを使用して、フォント名、サイズ、色、およびその他のプロパティを取得および設定します。
readonly font: Word.Font;
プロパティ値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/25-paragraph/insert-formatted-text.yaml
await Word.run(async (context) => {
// Insert the sentence, then adjust the formatting.
// Note that replace affects the calling object, in this case the entire document body.
// A similar method can also be used at the range level.
const sentence: Word.Range = context.document.body.insertText(
"This is some formatted text!",
"Replace"
);
sentence.font.set({
name: "Courier New",
bold: true,
size: 18
});
await context.sync();
});
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: Word.NoteItemCollection = context.document.getSelection().footnotes;
footnotes.load("length");
await context.sync();
console.log(`Number of footnotes in the selected range: ${footnotes.items.length}`);
});
frames
範囲内のすべてのフレームを表す FrameCollection オブジェクトを取得します。
readonly frames: Word.FrameCollection;
プロパティ値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/inspect-range-layout-desktop.yaml
// Reads the text and dimensions of frames in the document body range.
await Word.run(async (context) => {
const bodyRange: Word.Range = context.document.body.getRange();
const frames: Word.FrameCollection = bodyRange.frames;
frames.load("items/width,items/height,items/range/text");
await context.sync();
console.log(`Frames found: ${frames.items.length}`);
frames.items.forEach((frame: Word.Frame) => {
console.log({ width: frame.width, height: frame.height, text: frame.range.text });
});
});
grammarChecked
範囲またはドキュメントに対して文法チェックが実行されたかどうかを指定します。
grammarChecked: boolean;
プロパティ値
boolean
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/28-formatting/manage-language-and-proofing-desktop.yaml
// Marks the first paragraph as needing another grammar check.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange(Word.RangeLocation.content);
paragraphRange.grammarChecked = false;
await context.sync();
console.log("Reset the English paragraph's grammar-checked flag. Get language and proofing settings to inspect it.");
});
hasNoProofing
範囲の校正の状態 (スペル チェックと文法チェック) を指定します。
hasNoProofing: boolean;
プロパティ値
boolean
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/28-formatting/manage-language-and-proofing-desktop.yaml
// Disables spelling and grammar checking for the first paragraph.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange(Word.RangeLocation.content);
paragraphRange.hasNoProofing = true;
await context.sync();
console.log("Disabled spelling and grammar checking for the English paragraph. Get language and proofing settings to verify it.");
});
highlightColorIndex
範囲のハイライト カラーを指定します。
readonly highlightColorIndex: Word.ColorIndex | "Auto" | "Black" | "Blue" | "Turquoise" | "BrightGreen" | "Pink" | "Red" | "Yellow" | "White" | "DarkBlue" | "Teal" | "Green" | "Violet" | "DarkRed" | "DarkYellow" | "Gray50" | "Gray25" | "ClassicRed" | "ClassicBlue" | "ByAuthor";
プロパティ値
Word.ColorIndex | "Auto" | "Black" | "Blue" | "Turquoise" | "BrightGreen" | "Pink" | "Red" | "Yellow" | "White" | "DarkBlue" | "Teal" | "Green" | "Violet" | "DarkRed" | "DarkYellow" | "Gray50" | "Gray25" | "ClassicRed" | "ClassicBlue" | "ByAuthor"
注釈
horizontalInVertical
縦書きテキスト内に設定された横書きテキストの書式設定を指定します。
horizontalInVertical: Word.HorizontalInVerticalType | "None" | "FitInLine" | "ResizeLine";
プロパティ値
Word.HorizontalInVerticalType | "None" | "FitInLine" | "ResizeLine"
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/28-formatting/apply-character-layout-desktop.yaml
// Keeps the first paragraph's characters horizontal within vertical text.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange(Word.RangeLocation.content);
const horizontalLayout: Word.HorizontalInVerticalType = Word.HorizontalInVerticalType.fitInLine;
paragraphRange.horizontalInVertical = horizontalLayout;
await context.sync();
console.log("Enabled horizontal-in-vertical layout on the first paragraph. Get layout settings to verify it.");
});
hyperlink
範囲内の最初のハイパーリンクを取得するか、または範囲にハイパーリンクを設定します。 範囲に新しいハイパーリンクを設定すると、範囲内のすべてのハイパーリンクが削除されます。 住所の部分とオプションの場所の部分を区切るには、'#' を使用します。
hyperlink: string;
プロパティ値
string
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/inspect-range-structure.yaml
// Links the first paragraph's text to the Word add-in documentation.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange(Word.RangeLocation.content);
paragraphRange.hyperlink = "https://learn.microsoft.com/office/dev/add-ins/word/";
await context.sync();
console.log("Linked the summary text to the Word add-in documentation.");
});
hyperlinks
範囲内のすべてのハイパーリンクを表す HyperlinkCollection オブジェクトを返します。
readonly hyperlinks: Word.HyperlinkCollection;
プロパティ値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/inspect-range-layout-desktop.yaml
// Reads hyperlink objects and their destinations in the document body range.
await Word.run(async (context) => {
const bodyRange: Word.Range = context.document.body.getRange();
const hyperlinks: Word.HyperlinkCollection = bodyRange.hyperlinks;
hyperlinks.load("items/address,items/range/text");
await context.sync();
console.log(`Hyperlinks found: ${hyperlinks.items.length}`);
hyperlinks.items.forEach((hyperlink: Word.Hyperlink) => {
console.log({ address: hyperlink.address, text: hyperlink.range.text });
});
});
id
範囲の ID を指定します。
id: string;
プロパティ値
string
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/inspect-and-adjust-range-boundaries-desktop.yaml
// Reads the range's character positions and the story containing it.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange(Word.RangeLocation.content);
paragraphRange.load("id,start,end,storyLength,storyType,isEndOfRowMark,isTextVisibleOnScreen");
await context.sync();
console.log("First paragraph's position and story:", {
id: paragraphRange.id,
start: paragraphRange.start,
end: paragraphRange.end,
storyLength: paragraphRange.storyLength,
storyType: paragraphRange.storyType,
isEndOfRowMark: paragraphRange.isEndOfRowMark,
isTextVisibleOnScreen: paragraphRange.isTextVisibleOnScreen
});
});
inlinePictures
範囲内の InlinePicture オブジェクトのコレクションを取得します。
readonly inlinePictures: Word.InlinePictureCollection;
プロパティ値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/inspect-range-structure.yaml
// Reads the dimensions of inline pictures in the document body range.
await Word.run(async (context) => {
const bodyRange: Word.Range = context.document.body.getRange();
const pictures: Word.InlinePictureCollection = bodyRange.inlinePictures;
pictures.load("items/width,items/height");
await context.sync();
console.log(`Inline pictures found: ${pictures.items.length}`);
pictures.items.forEach((picture: Word.InlinePicture) => console.log({ width: picture.width, height: picture.height }));
});
isEmpty
isEndOfRowMark
範囲が折りたたまれていて、テーブルの行末のマークにあるかどうかを取得します。
readonly isEndOfRowMark: boolean;
プロパティ値
boolean
注釈
isTextVisibleOnScreen
範囲内のテキストが画面に表示されているかどうかを取得します。
readonly isTextVisibleOnScreen: boolean;
プロパティ値
boolean
注釈
italic
フォントまたは範囲を斜体として書式設定するかどうかを指定します。
readonly italic: boolean;
プロパティ値
boolean
注釈
italicBidirectional
フォントまたは範囲を斜体 (右から左の言語) として書式設定するかどうかを指定します。
readonly italicBidirectional: boolean;
プロパティ値
boolean
注釈
kana
日本語のテキストの範囲がひらがなかカタカナかを指定します。
kana: Word.Kana | "Katakana" | "Hiragana";
プロパティ値
Word.Kana | "Katakana" | "Hiragana"
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/28-formatting/convert-japanese-kana-desktop.yaml
// Converts the sample paragraph's Japanese katakana text to hiragana.
await Word.run(async (context) => {
const japaneseRange: Word.Range = context.document.body.paragraphs.getFirst().getRange(Word.RangeLocation.content);
const kana: Word.Kana = Word.Kana.hiragana;
japaneseRange.kana = kana;
await context.sync();
console.log("Converted the Japanese paragraph's text to hiragana.");
});
languageDetected
Microsoft Word が範囲内のテキストの言語を検出したかどうかを指定します。
languageDetected: boolean;
プロパティ値
boolean
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/28-formatting/manage-language-and-proofing-desktop.yaml
// Marks the first paragraph's language as not yet detected.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange(Word.RangeLocation.content);
paragraphRange.languageDetected = false;
await context.sync();
console.log("Reset the English paragraph's language-detected flag. Get language and proofing settings to inspect it.");
});
languageId
範囲の言語を表す LanguageId 値を指定します。
languageId: Word.LanguageId | "Afrikaans" | "Albanian" | "Amharic" | "Arabic" | "ArabicAlgeria" | "ArabicBahrain" | "ArabicEgypt" | "ArabicIraq" | "ArabicJordan" | "ArabicKuwait" | "ArabicLebanon" | "ArabicLibya" | "ArabicMorocco" | "ArabicOman" | "ArabicQatar" | "ArabicSyria" | "ArabicTunisia" | "ArabicUAE" | "ArabicYemen" | "Armenian" | "Assamese" | "AzeriCyrillic" | "AzeriLatin" | "Basque" | "BelgianDutch" | "BelgianFrench" | "Bengali" | "Bulgarian" | "Burmese" | "Belarusian" | "Catalan" | "Cherokee" | "ChineseHongKongSAR" | "ChineseMacaoSAR" | "ChineseSingapore" | "Croatian" | "Czech" | "Danish" | "Divehi" | "Dutch" | "Edo" | "EnglishAUS" | "EnglishBelize" | "EnglishCanadian" | "EnglishCaribbean" | "EnglishIndonesia" | "EnglishIreland" | "EnglishJamaica" | "EnglishNewZealand" | "EnglishPhilippines" | "EnglishSouthAfrica" | "EnglishTrinidadTobago" | "EnglishUK" | "EnglishUS" | "EnglishZimbabwe" | "Estonian" | "Faeroese" | "Filipino" | "Finnish" | "French" | "FrenchCameroon" | "FrenchCanadian" | "FrenchCongoDRC" | "FrenchCotedIvoire" | "FrenchHaiti" | "FrenchLuxembourg" | "FrenchMali" | "FrenchMonaco" | "FrenchMorocco" | "FrenchReunion" | "FrenchSenegal" | "FrenchWestIndies" | "FrisianNetherlands" | "Fulfulde" | "GaelicIreland" | "GaelicScotland" | "Galician" | "Georgian" | "German" | "GermanAustria" | "GermanLiechtenstein" | "GermanLuxembourg" | "Greek" | "Guarani" | "Gujarati" | "Hausa" | "Hawaiian" | "Hebrew" | "Hindi" | "Hungarian" | "Ibibio" | "Icelandic" | "Igbo" | "Indonesian" | "Inuktitut" | "Italian" | "Japanese" | "Kannada" | "Kanuri" | "Kashmiri" | "Kazakh" | "Khmer" | "Kirghiz" | "Konkani" | "Korean" | "Kyrgyz" | "LanguageNone" | "Lao" | "Latin" | "Latvian" | "Lithuanian" | "MacedonianFYROM" | "Malayalam" | "MalayBruneiDarussalam" | "Malaysian" | "Maltese" | "Manipuri" | "Marathi" | "MexicanSpanish" | "Mongolian" | "Nepali" | "NoProofing" | "NorwegianBokmol" | "NorwegianNynorsk" | "Oriya" | "Oromo" | "Pashto" | "Persian" | "Polish" | "Portuguese" | "PortugueseBrazil" | "Punjabi" | "RhaetoRomanic" | "Romanian" | "RomanianMoldova" | "Russian" | "RussianMoldova" | "SamiLappish" | "Sanskrit" | "SerbianCyrillic" | "SerbianLatin" | "Sesotho" | "SimplifiedChinese" | "Sindhi" | "SindhiPakistan" | "Sinhalese" | "Slovak" | "Slovenian" | "Somali" | "Sorbian" | "Spanish" | "SpanishArgentina" | "SpanishBolivia" | "SpanishChile" | "SpanishColombia" | "SpanishCostaRica" | "SpanishDominicanRepublic" | "SpanishEcuador" | "SpanishElSalvador" | "SpanishGuatemala" | "SpanishHonduras" | "SpanishModernSort" | "SpanishNicaragua" | "SpanishPanama" | "SpanishParaguay" | "SpanishPeru" | "SpanishPuertoRico" | "SpanishUruguay" | "SpanishVenezuela" | "Sutu" | "Swahili" | "Swedish" | "SwedishFinland" | "SwissFrench" | "SwissGerman" | "SwissItalian" | "Syriac" | "Tajik" | "Tamazight" | "TamazightLatin" | "Tamil" | "Tatar" | "Telugu" | "Thai" | "Tibetan" | "TigrignaEritrea" | "TigrignaEthiopic" | "TraditionalChinese" | "Tsonga" | "Tswana" | "Turkish" | "Turkmen" | "Ukrainian" | "Urdu" | "UzbekCyrillic" | "UzbekLatin" | "Venda" | "Vietnamese" | "Welsh" | "Xhosa" | "Yi" | "Yiddish" | "Yoruba" | "Zulu";
プロパティ値
Word.LanguageId | "Afrikaans" | "Albanian" | "Amharic" | "Arabic" | "ArabicAlgeria" | "ArabicBahrain" | "ArabicEgypt" | "ArabicIraq" | "ArabicJordan" | "ArabicKuwait" | "ArabicLebanon" | "ArabicLibya" | "ArabicMorocco" | "ArabicOman" | "ArabicQatar" | "ArabicSyria" | "ArabicTunisia" | "ArabicUAE" | "ArabicYemen" | "Armenian" | "Assamese" | "AzeriCyrillic" | "AzeriLatin" | "Basque" | "BelgianDutch" | "BelgianFrench" | "Bengali" | "Bulgarian" | "Burmese" | "Belarusian" | "Catalan" | "Cherokee" | "ChineseHongKongSAR" | "ChineseMacaoSAR" | "ChineseSingapore" | "Croatian" | "Czech" | "Danish" | "Divehi" | "Dutch" | "Edo" | "EnglishAUS" | "EnglishBelize" | "EnglishCanadian" | "EnglishCaribbean" | "EnglishIndonesia" | "EnglishIreland" | "EnglishJamaica" | "EnglishNewZealand" | "EnglishPhilippines" | "EnglishSouthAfrica" | "EnglishTrinidadTobago" | "EnglishUK" | "EnglishUS" | "EnglishZimbabwe" | "Estonian" | "Faeroese" | "Filipino" | "Finnish" | "French" | "FrenchCameroon" | "FrenchCanadian" | "FrenchCongoDRC" | "FrenchCotedIvoire" | "FrenchHaiti" | "FrenchLuxembourg" | "FrenchMali" | "FrenchMonaco" | "FrenchMorocco" | "FrenchReunion" | "FrenchSenegal" | "FrenchWestIndies" | "FrisianNetherlands" | "Fulfulde" | "GaelicIreland" | "GaelicScotland" | "Galician" | "Georgian" | "German" | "GermanAustria" | "GermanLiechtenstein" | "GermanLuxembourg" | "Greek" | "Guarani" | "Gujarati" | "Hausa" | "Hawaiian" | "Hebrew" | "Hindi" | "Hungarian" | "Ibibio" | "Icelandic" | "Igbo" | "Indonesian" | "Inuktitut" | "Italian" | "Japanese" | "Kannada" | "Kanuri" | "Kashmiri" | "Kazakh" | "Khmer" | "Kirghiz" | "Konkani" | "Korean" | "Kyrgyz" | "LanguageNone" | "Lao" | "Latin" | "Latvian" | "Lithuanian" | "MacedonianFYROM" | "Malayalam" | "MalayBruneiDarussalam" | "Malaysian" | "Maltese" | "Manipuri" | "Marathi" | "MexicanSpanish" | "Mongolian" | "Nepali" | "NoProofing" | "NorwegianBokmol" | "NorwegianNynorsk" | "Oriya" | "Oromo" | "Pashto" | "Persian" | "Polish" | "Portuguese" | "PortugueseBrazil" | "Punjabi" | "RhaetoRomanic" | "Romanian" | "RomanianMoldova" | "Russian" | "RussianMoldova" | "SamiLappish" | "Sanskrit" | "SerbianCyrillic" | "SerbianLatin" | "Sesotho" | "SimplifiedChinese" | "Sindhi" | "SindhiPakistan" | "Sinhalese" | "Slovak" | "Slovenian" | "Somali" | "Sorbian" | "Spanish" | "SpanishArgentina" | "SpanishBolivia" | "SpanishChile" | "SpanishColombia" | "SpanishCostaRica" | "SpanishDominicanRepublic" | "SpanishEcuador" | "SpanishElSalvador" | "SpanishGuatemala" | "SpanishHonduras" | "SpanishModernSort" | "SpanishNicaragua" | "SpanishPanama" | "SpanishParaguay" | "SpanishPeru" | "SpanishPuertoRico" | "SpanishUruguay" | "SpanishVenezuela" | "Sutu" | "Swahili" | "Swedish" | "SwedishFinland" | "SwissFrench" | "SwissGerman" | "SwissItalian" | "Syriac" | "Tajik" | "Tamazight" | "TamazightLatin" | "Tamil" | "Tatar" | "Telugu" | "Thai" | "Tibetan" | "TigrignaEritrea" | "TigrignaEthiopic" | "TraditionalChinese" | "Tsonga" | "Tswana" | "Turkish" | "Turkmen" | "Ukrainian" | "Urdu" | "UzbekCyrillic" | "UzbekLatin" | "Venda" | "Vietnamese" | "Welsh" | "Xhosa" | "Yi" | "Yiddish" | "Yoruba" | "Zulu"
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/28-formatting/manage-language-and-proofing-desktop.yaml
// Sets the first paragraph's proofing language to US English.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange(Word.RangeLocation.content);
const language: Word.LanguageId = Word.LanguageId.englishUS;
paragraphRange.languageId = language;
await context.sync();
console.log("Set the English paragraph's proofing language to US English.");
});
languageIdFarEast
範囲の東アジア言語を指定します。
languageIdFarEast: Word.LanguageId | "Afrikaans" | "Albanian" | "Amharic" | "Arabic" | "ArabicAlgeria" | "ArabicBahrain" | "ArabicEgypt" | "ArabicIraq" | "ArabicJordan" | "ArabicKuwait" | "ArabicLebanon" | "ArabicLibya" | "ArabicMorocco" | "ArabicOman" | "ArabicQatar" | "ArabicSyria" | "ArabicTunisia" | "ArabicUAE" | "ArabicYemen" | "Armenian" | "Assamese" | "AzeriCyrillic" | "AzeriLatin" | "Basque" | "BelgianDutch" | "BelgianFrench" | "Bengali" | "Bulgarian" | "Burmese" | "Belarusian" | "Catalan" | "Cherokee" | "ChineseHongKongSAR" | "ChineseMacaoSAR" | "ChineseSingapore" | "Croatian" | "Czech" | "Danish" | "Divehi" | "Dutch" | "Edo" | "EnglishAUS" | "EnglishBelize" | "EnglishCanadian" | "EnglishCaribbean" | "EnglishIndonesia" | "EnglishIreland" | "EnglishJamaica" | "EnglishNewZealand" | "EnglishPhilippines" | "EnglishSouthAfrica" | "EnglishTrinidadTobago" | "EnglishUK" | "EnglishUS" | "EnglishZimbabwe" | "Estonian" | "Faeroese" | "Filipino" | "Finnish" | "French" | "FrenchCameroon" | "FrenchCanadian" | "FrenchCongoDRC" | "FrenchCotedIvoire" | "FrenchHaiti" | "FrenchLuxembourg" | "FrenchMali" | "FrenchMonaco" | "FrenchMorocco" | "FrenchReunion" | "FrenchSenegal" | "FrenchWestIndies" | "FrisianNetherlands" | "Fulfulde" | "GaelicIreland" | "GaelicScotland" | "Galician" | "Georgian" | "German" | "GermanAustria" | "GermanLiechtenstein" | "GermanLuxembourg" | "Greek" | "Guarani" | "Gujarati" | "Hausa" | "Hawaiian" | "Hebrew" | "Hindi" | "Hungarian" | "Ibibio" | "Icelandic" | "Igbo" | "Indonesian" | "Inuktitut" | "Italian" | "Japanese" | "Kannada" | "Kanuri" | "Kashmiri" | "Kazakh" | "Khmer" | "Kirghiz" | "Konkani" | "Korean" | "Kyrgyz" | "LanguageNone" | "Lao" | "Latin" | "Latvian" | "Lithuanian" | "MacedonianFYROM" | "Malayalam" | "MalayBruneiDarussalam" | "Malaysian" | "Maltese" | "Manipuri" | "Marathi" | "MexicanSpanish" | "Mongolian" | "Nepali" | "NoProofing" | "NorwegianBokmol" | "NorwegianNynorsk" | "Oriya" | "Oromo" | "Pashto" | "Persian" | "Polish" | "Portuguese" | "PortugueseBrazil" | "Punjabi" | "RhaetoRomanic" | "Romanian" | "RomanianMoldova" | "Russian" | "RussianMoldova" | "SamiLappish" | "Sanskrit" | "SerbianCyrillic" | "SerbianLatin" | "Sesotho" | "SimplifiedChinese" | "Sindhi" | "SindhiPakistan" | "Sinhalese" | "Slovak" | "Slovenian" | "Somali" | "Sorbian" | "Spanish" | "SpanishArgentina" | "SpanishBolivia" | "SpanishChile" | "SpanishColombia" | "SpanishCostaRica" | "SpanishDominicanRepublic" | "SpanishEcuador" | "SpanishElSalvador" | "SpanishGuatemala" | "SpanishHonduras" | "SpanishModernSort" | "SpanishNicaragua" | "SpanishPanama" | "SpanishParaguay" | "SpanishPeru" | "SpanishPuertoRico" | "SpanishUruguay" | "SpanishVenezuela" | "Sutu" | "Swahili" | "Swedish" | "SwedishFinland" | "SwissFrench" | "SwissGerman" | "SwissItalian" | "Syriac" | "Tajik" | "Tamazight" | "TamazightLatin" | "Tamil" | "Tatar" | "Telugu" | "Thai" | "Tibetan" | "TigrignaEritrea" | "TigrignaEthiopic" | "TraditionalChinese" | "Tsonga" | "Tswana" | "Turkish" | "Turkmen" | "Ukrainian" | "Urdu" | "UzbekCyrillic" | "UzbekLatin" | "Venda" | "Vietnamese" | "Welsh" | "Xhosa" | "Yi" | "Yiddish" | "Yoruba" | "Zulu";
プロパティ値
Word.LanguageId | "Afrikaans" | "Albanian" | "Amharic" | "Arabic" | "ArabicAlgeria" | "ArabicBahrain" | "ArabicEgypt" | "ArabicIraq" | "ArabicJordan" | "ArabicKuwait" | "ArabicLebanon" | "ArabicLibya" | "ArabicMorocco" | "ArabicOman" | "ArabicQatar" | "ArabicSyria" | "ArabicTunisia" | "ArabicUAE" | "ArabicYemen" | "Armenian" | "Assamese" | "AzeriCyrillic" | "AzeriLatin" | "Basque" | "BelgianDutch" | "BelgianFrench" | "Bengali" | "Bulgarian" | "Burmese" | "Belarusian" | "Catalan" | "Cherokee" | "ChineseHongKongSAR" | "ChineseMacaoSAR" | "ChineseSingapore" | "Croatian" | "Czech" | "Danish" | "Divehi" | "Dutch" | "Edo" | "EnglishAUS" | "EnglishBelize" | "EnglishCanadian" | "EnglishCaribbean" | "EnglishIndonesia" | "EnglishIreland" | "EnglishJamaica" | "EnglishNewZealand" | "EnglishPhilippines" | "EnglishSouthAfrica" | "EnglishTrinidadTobago" | "EnglishUK" | "EnglishUS" | "EnglishZimbabwe" | "Estonian" | "Faeroese" | "Filipino" | "Finnish" | "French" | "FrenchCameroon" | "FrenchCanadian" | "FrenchCongoDRC" | "FrenchCotedIvoire" | "FrenchHaiti" | "FrenchLuxembourg" | "FrenchMali" | "FrenchMonaco" | "FrenchMorocco" | "FrenchReunion" | "FrenchSenegal" | "FrenchWestIndies" | "FrisianNetherlands" | "Fulfulde" | "GaelicIreland" | "GaelicScotland" | "Galician" | "Georgian" | "German" | "GermanAustria" | "GermanLiechtenstein" | "GermanLuxembourg" | "Greek" | "Guarani" | "Gujarati" | "Hausa" | "Hawaiian" | "Hebrew" | "Hindi" | "Hungarian" | "Ibibio" | "Icelandic" | "Igbo" | "Indonesian" | "Inuktitut" | "Italian" | "Japanese" | "Kannada" | "Kanuri" | "Kashmiri" | "Kazakh" | "Khmer" | "Kirghiz" | "Konkani" | "Korean" | "Kyrgyz" | "LanguageNone" | "Lao" | "Latin" | "Latvian" | "Lithuanian" | "MacedonianFYROM" | "Malayalam" | "MalayBruneiDarussalam" | "Malaysian" | "Maltese" | "Manipuri" | "Marathi" | "MexicanSpanish" | "Mongolian" | "Nepali" | "NoProofing" | "NorwegianBokmol" | "NorwegianNynorsk" | "Oriya" | "Oromo" | "Pashto" | "Persian" | "Polish" | "Portuguese" | "PortugueseBrazil" | "Punjabi" | "RhaetoRomanic" | "Romanian" | "RomanianMoldova" | "Russian" | "RussianMoldova" | "SamiLappish" | "Sanskrit" | "SerbianCyrillic" | "SerbianLatin" | "Sesotho" | "SimplifiedChinese" | "Sindhi" | "SindhiPakistan" | "Sinhalese" | "Slovak" | "Slovenian" | "Somali" | "Sorbian" | "Spanish" | "SpanishArgentina" | "SpanishBolivia" | "SpanishChile" | "SpanishColombia" | "SpanishCostaRica" | "SpanishDominicanRepublic" | "SpanishEcuador" | "SpanishElSalvador" | "SpanishGuatemala" | "SpanishHonduras" | "SpanishModernSort" | "SpanishNicaragua" | "SpanishPanama" | "SpanishParaguay" | "SpanishPeru" | "SpanishPuertoRico" | "SpanishUruguay" | "SpanishVenezuela" | "Sutu" | "Swahili" | "Swedish" | "SwedishFinland" | "SwissFrench" | "SwissGerman" | "SwissItalian" | "Syriac" | "Tajik" | "Tamazight" | "TamazightLatin" | "Tamil" | "Tatar" | "Telugu" | "Thai" | "Tibetan" | "TigrignaEritrea" | "TigrignaEthiopic" | "TraditionalChinese" | "Tsonga" | "Tswana" | "Turkish" | "Turkmen" | "Ukrainian" | "Urdu" | "UzbekCyrillic" | "UzbekLatin" | "Venda" | "Vietnamese" | "Welsh" | "Xhosa" | "Yi" | "Yiddish" | "Yoruba" | "Zulu"
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/28-formatting/manage-language-and-proofing-desktop.yaml
// Sets the Japanese paragraph's East Asian language.
await Word.run(async (context) => {
const japaneseRange: Word.Range = context.document.body.paragraphs.getLast().getRange(Word.RangeLocation.content);
const language: Word.LanguageId = Word.LanguageId.japanese;
japaneseRange.languageIdFarEast = language;
await context.sync();
console.log("Set the Japanese paragraph's East Asian language to Japanese.");
});
languageIdOther
東アジア言語として分類されていない範囲の言語を指定します。
languageIdOther: Word.LanguageId | "Afrikaans" | "Albanian" | "Amharic" | "Arabic" | "ArabicAlgeria" | "ArabicBahrain" | "ArabicEgypt" | "ArabicIraq" | "ArabicJordan" | "ArabicKuwait" | "ArabicLebanon" | "ArabicLibya" | "ArabicMorocco" | "ArabicOman" | "ArabicQatar" | "ArabicSyria" | "ArabicTunisia" | "ArabicUAE" | "ArabicYemen" | "Armenian" | "Assamese" | "AzeriCyrillic" | "AzeriLatin" | "Basque" | "BelgianDutch" | "BelgianFrench" | "Bengali" | "Bulgarian" | "Burmese" | "Belarusian" | "Catalan" | "Cherokee" | "ChineseHongKongSAR" | "ChineseMacaoSAR" | "ChineseSingapore" | "Croatian" | "Czech" | "Danish" | "Divehi" | "Dutch" | "Edo" | "EnglishAUS" | "EnglishBelize" | "EnglishCanadian" | "EnglishCaribbean" | "EnglishIndonesia" | "EnglishIreland" | "EnglishJamaica" | "EnglishNewZealand" | "EnglishPhilippines" | "EnglishSouthAfrica" | "EnglishTrinidadTobago" | "EnglishUK" | "EnglishUS" | "EnglishZimbabwe" | "Estonian" | "Faeroese" | "Filipino" | "Finnish" | "French" | "FrenchCameroon" | "FrenchCanadian" | "FrenchCongoDRC" | "FrenchCotedIvoire" | "FrenchHaiti" | "FrenchLuxembourg" | "FrenchMali" | "FrenchMonaco" | "FrenchMorocco" | "FrenchReunion" | "FrenchSenegal" | "FrenchWestIndies" | "FrisianNetherlands" | "Fulfulde" | "GaelicIreland" | "GaelicScotland" | "Galician" | "Georgian" | "German" | "GermanAustria" | "GermanLiechtenstein" | "GermanLuxembourg" | "Greek" | "Guarani" | "Gujarati" | "Hausa" | "Hawaiian" | "Hebrew" | "Hindi" | "Hungarian" | "Ibibio" | "Icelandic" | "Igbo" | "Indonesian" | "Inuktitut" | "Italian" | "Japanese" | "Kannada" | "Kanuri" | "Kashmiri" | "Kazakh" | "Khmer" | "Kirghiz" | "Konkani" | "Korean" | "Kyrgyz" | "LanguageNone" | "Lao" | "Latin" | "Latvian" | "Lithuanian" | "MacedonianFYROM" | "Malayalam" | "MalayBruneiDarussalam" | "Malaysian" | "Maltese" | "Manipuri" | "Marathi" | "MexicanSpanish" | "Mongolian" | "Nepali" | "NoProofing" | "NorwegianBokmol" | "NorwegianNynorsk" | "Oriya" | "Oromo" | "Pashto" | "Persian" | "Polish" | "Portuguese" | "PortugueseBrazil" | "Punjabi" | "RhaetoRomanic" | "Romanian" | "RomanianMoldova" | "Russian" | "RussianMoldova" | "SamiLappish" | "Sanskrit" | "SerbianCyrillic" | "SerbianLatin" | "Sesotho" | "SimplifiedChinese" | "Sindhi" | "SindhiPakistan" | "Sinhalese" | "Slovak" | "Slovenian" | "Somali" | "Sorbian" | "Spanish" | "SpanishArgentina" | "SpanishBolivia" | "SpanishChile" | "SpanishColombia" | "SpanishCostaRica" | "SpanishDominicanRepublic" | "SpanishEcuador" | "SpanishElSalvador" | "SpanishGuatemala" | "SpanishHonduras" | "SpanishModernSort" | "SpanishNicaragua" | "SpanishPanama" | "SpanishParaguay" | "SpanishPeru" | "SpanishPuertoRico" | "SpanishUruguay" | "SpanishVenezuela" | "Sutu" | "Swahili" | "Swedish" | "SwedishFinland" | "SwissFrench" | "SwissGerman" | "SwissItalian" | "Syriac" | "Tajik" | "Tamazight" | "TamazightLatin" | "Tamil" | "Tatar" | "Telugu" | "Thai" | "Tibetan" | "TigrignaEritrea" | "TigrignaEthiopic" | "TraditionalChinese" | "Tsonga" | "Tswana" | "Turkish" | "Turkmen" | "Ukrainian" | "Urdu" | "UzbekCyrillic" | "UzbekLatin" | "Venda" | "Vietnamese" | "Welsh" | "Xhosa" | "Yi" | "Yiddish" | "Yoruba" | "Zulu";
プロパティ値
Word.LanguageId | "Afrikaans" | "Albanian" | "Amharic" | "Arabic" | "ArabicAlgeria" | "ArabicBahrain" | "ArabicEgypt" | "ArabicIraq" | "ArabicJordan" | "ArabicKuwait" | "ArabicLebanon" | "ArabicLibya" | "ArabicMorocco" | "ArabicOman" | "ArabicQatar" | "ArabicSyria" | "ArabicTunisia" | "ArabicUAE" | "ArabicYemen" | "Armenian" | "Assamese" | "AzeriCyrillic" | "AzeriLatin" | "Basque" | "BelgianDutch" | "BelgianFrench" | "Bengali" | "Bulgarian" | "Burmese" | "Belarusian" | "Catalan" | "Cherokee" | "ChineseHongKongSAR" | "ChineseMacaoSAR" | "ChineseSingapore" | "Croatian" | "Czech" | "Danish" | "Divehi" | "Dutch" | "Edo" | "EnglishAUS" | "EnglishBelize" | "EnglishCanadian" | "EnglishCaribbean" | "EnglishIndonesia" | "EnglishIreland" | "EnglishJamaica" | "EnglishNewZealand" | "EnglishPhilippines" | "EnglishSouthAfrica" | "EnglishTrinidadTobago" | "EnglishUK" | "EnglishUS" | "EnglishZimbabwe" | "Estonian" | "Faeroese" | "Filipino" | "Finnish" | "French" | "FrenchCameroon" | "FrenchCanadian" | "FrenchCongoDRC" | "FrenchCotedIvoire" | "FrenchHaiti" | "FrenchLuxembourg" | "FrenchMali" | "FrenchMonaco" | "FrenchMorocco" | "FrenchReunion" | "FrenchSenegal" | "FrenchWestIndies" | "FrisianNetherlands" | "Fulfulde" | "GaelicIreland" | "GaelicScotland" | "Galician" | "Georgian" | "German" | "GermanAustria" | "GermanLiechtenstein" | "GermanLuxembourg" | "Greek" | "Guarani" | "Gujarati" | "Hausa" | "Hawaiian" | "Hebrew" | "Hindi" | "Hungarian" | "Ibibio" | "Icelandic" | "Igbo" | "Indonesian" | "Inuktitut" | "Italian" | "Japanese" | "Kannada" | "Kanuri" | "Kashmiri" | "Kazakh" | "Khmer" | "Kirghiz" | "Konkani" | "Korean" | "Kyrgyz" | "LanguageNone" | "Lao" | "Latin" | "Latvian" | "Lithuanian" | "MacedonianFYROM" | "Malayalam" | "MalayBruneiDarussalam" | "Malaysian" | "Maltese" | "Manipuri" | "Marathi" | "MexicanSpanish" | "Mongolian" | "Nepali" | "NoProofing" | "NorwegianBokmol" | "NorwegianNynorsk" | "Oriya" | "Oromo" | "Pashto" | "Persian" | "Polish" | "Portuguese" | "PortugueseBrazil" | "Punjabi" | "RhaetoRomanic" | "Romanian" | "RomanianMoldova" | "Russian" | "RussianMoldova" | "SamiLappish" | "Sanskrit" | "SerbianCyrillic" | "SerbianLatin" | "Sesotho" | "SimplifiedChinese" | "Sindhi" | "SindhiPakistan" | "Sinhalese" | "Slovak" | "Slovenian" | "Somali" | "Sorbian" | "Spanish" | "SpanishArgentina" | "SpanishBolivia" | "SpanishChile" | "SpanishColombia" | "SpanishCostaRica" | "SpanishDominicanRepublic" | "SpanishEcuador" | "SpanishElSalvador" | "SpanishGuatemala" | "SpanishHonduras" | "SpanishModernSort" | "SpanishNicaragua" | "SpanishPanama" | "SpanishParaguay" | "SpanishPeru" | "SpanishPuertoRico" | "SpanishUruguay" | "SpanishVenezuela" | "Sutu" | "Swahili" | "Swedish" | "SwedishFinland" | "SwissFrench" | "SwissGerman" | "SwissItalian" | "Syriac" | "Tajik" | "Tamazight" | "TamazightLatin" | "Tamil" | "Tatar" | "Telugu" | "Thai" | "Tibetan" | "TigrignaEritrea" | "TigrignaEthiopic" | "TraditionalChinese" | "Tsonga" | "Tswana" | "Turkish" | "Turkmen" | "Ukrainian" | "Urdu" | "UzbekCyrillic" | "UzbekLatin" | "Venda" | "Vietnamese" | "Welsh" | "Xhosa" | "Yi" | "Yiddish" | "Yoruba" | "Zulu"
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/28-formatting/manage-language-and-proofing-desktop.yaml
// Sets the first paragraph's non-East-Asian language to US English.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange(Word.RangeLocation.content);
const language: Word.LanguageId = Word.LanguageId.englishUS;
paragraphRange.languageIdOther = language;
await context.sync();
console.log("Set the English paragraph's non-East-Asian language to US English.");
});
listFormat
範囲のリストの書式設定上のすべての特性を表す ListFormat オブジェクトを返します。
readonly listFormat: Word.ListFormat;
プロパティ値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/20-lists/format-list-range.yaml
// Gets the range covering the entire body and reads list formatting properties.
await Word.run(async (context) => {
const bodyRange: Word.Range = context.document.body.getRange();
const listFormat: Word.ListFormat = bodyRange.listFormat;
listFormat.load("isSingleList, listType, listLevelNumber, listString, listValue");
await context.sync();
console.log("List format info for the body range:");
console.log(`- Is single list: ${listFormat.isSingleList}`);
console.log(`- List type: ${listFormat.listType}`);
console.log(`- List level number (first paragraph): ${listFormat.listLevelNumber}`);
console.log(`- List string (first paragraph): "${listFormat.listString}"`);
console.log(`- List value (first paragraph): ${listFormat.listValue}`);
});
lists
範囲内の List オブジェクトのコレクションを取得します。
readonly lists: Word.ListCollection;
プロパティ値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/inspect-range-structure.yaml
// Reads the identifiers of lists in the document body range.
await Word.run(async (context) => {
const bodyRange: Word.Range = context.document.body.getRange();
const lists: Word.ListCollection = bodyRange.lists;
lists.load("items/id");
await context.sync();
console.log(`Lists found: ${lists.items.length}`);
lists.items.forEach((list: Word.List) => console.log(`List ID: ${list.id}`));
});
pages
範囲内のページのコレクションを取得します。
readonly pages: Word.PageCollection;
プロパティ値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/36-pages/get-pages.yaml
// Reads the index and text of each page intersecting the selection.
await Word.run(async (context) => {
const selectedRange: Word.Range = context.document.getSelection();
const pages: Word.PageCollection = selectedRange.pages;
pages.load("items/index");
await context.sync();
console.log(`Pages in the selection: ${pages.items.length}`);
const pageRanges: Word.Range[] = [];
pages.items.forEach((page: Word.Page) => {
const pageRange: Word.Range = page.getRange(Word.RangeLocation.whole);
pageRange.load("text");
pageRanges.push(pageRange);
});
await context.sync();
for (let i = 0; i < pages.items.length; i++) {
console.log(`Page ${pages.items[i].index} text: ${pageRanges[i].text}`);
}
});
paragraphs
範囲内の Paragraph オブジェクトのコレクションを取得します。
readonly paragraphs: Word.ParagraphCollection;
プロパティ値
注釈
重要: 要件セット 1.1 および 1.2 の場合、この範囲内に完全に含まれるテーブル内の段落は返されません。 要件セット 1.3 から、このようなテーブルの段落も返されます。
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-annotations.yaml
// Accepts the first annotation found in the selected paragraph.
await Word.run(async (context) => {
const paragraph: Word.Paragraph = context.document.getSelection().paragraphs.getFirst();
const annotations: Word.AnnotationCollection = paragraph.getAnnotations();
annotations.load("id,state,critiqueAnnotation");
await context.sync();
for (let i = 0; i < annotations.items.length; i++) {
const annotation: Word.Annotation = annotations.items[i];
if (annotation.state === Word.AnnotationState.created) {
console.log(`Accepting ID ${annotation.id}...`);
annotation.critiqueAnnotation.accept();
await context.sync();
break;
}
}
});
parentBody
範囲の親の本文を取得します。
readonly parentBody: Word.Body;
プロパティ値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/insert-section-breaks.yaml
// Gets the section after the current selection when another section is expected.
await Word.run(async (context) => {
const selection: Word.Range = context.document.getSelection();
const selectedBody: Word.Body = selection.parentBody;
const selectedSection: Word.Section = selectedBody.parentSection;
const nextSection: Word.Section = selectedSection.getNext();
const nextSectionBody: Word.Body = nextSection.body;
nextSectionBody.load("text");
await context.sync();
console.log(`Next section text: ${nextSectionBody.text}`);
});
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: Word.Range = 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: Word.ContentControl = 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;
プロパティ値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/10-content-controls/insert-and-change-date-picker-content-control.yaml
// Deletes the first date picker content control found in the selection.
await Word.run(async (context) => {
// First, look if the selection contains a date picker content control.
const selectedRange: Word.Range = context.document.getSelection();
let selectedContentControl = selectedRange
.getContentControls({
types: [Word.ContentControlType.datePicker]
})
.getFirstOrNullObject();
selectedContentControl.load("id");
await context.sync();
// The selection doesn't contain a date picker, but the cursor might be inside one.
// Check if the selection's parent content control is a date picker.
if (selectedContentControl.isNullObject) {
const parentContentControl: Word.ContentControl = selectedRange.parentContentControlOrNullObject;
parentContentControl.load("id,type");
await context.sync();
if (parentContentControl.isNullObject || parentContentControl.type !== Word.ContentControlType.datePicker) {
console.warn("Please select a date picker content control before selecting Delete.");
return;
}
selectedContentControl = parentContentControl;
}
console.log(`About to delete date picker content control with ID: ${selectedContentControl.id}`);
selectedContentControl.delete(false);
await context.sync();
console.log("Deleted date picker content control.");
});
parentTable
範囲を含むテーブルを取得します。 テーブルに含まれない場合は、 ItemNotFound エラーをスローします。
readonly parentTable: Word.Table;
プロパティ値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/inspect-range-structure.yaml
// Reads the table containing the first table cell's range.
await Word.run(async (context) => {
const cellRange: Word.Range = context.document.body.tables.getFirst().getCell(0, 0).body.getRange();
const parentTable: Word.Table = cellRange.parentTable;
parentTable.load("rowCount,values");
await context.sync();
console.log("Parent table:", { rowCount: parentTable.rowCount, values: parentTable.values });
});
parentTableCell
範囲を含むテーブルのセルを取得します。 テーブル セルに含まれない場合は、 ItemNotFound エラーをスローします。
readonly parentTableCell: Word.TableCell;
プロパティ値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/inspect-range-structure.yaml
// Reads the cell containing the first table cell's range.
await Word.run(async (context) => {
const cellRange: Word.Range = context.document.body.tables.getFirst().getCell(0, 0).body.getRange();
const parentCell: Word.TableCell = cellRange.parentTableCell;
parentCell.load("rowIndex,cellIndex,value");
await context.sync();
console.log("Parent cell:", { rowIndex: parentCell.rowIndex, cellIndex: parentCell.cellIndex, value: parentCell.value });
});
parentTableCellOrNullObject
範囲を含むテーブルのセルを取得します。 テーブルのセルに含まれない場合、このメソッドは、 isNullObject プロパティが true に設定されたオブジェクトを返します。 詳細については、「 *OrNullObject のメソッドとプロパティ」を参照してください。
readonly parentTableCellOrNullObject: Word.TableCell;
プロパティ値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/inspect-range-structure.yaml
// Checks whether the first paragraph is inside a table cell.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange();
const parentCell: Word.TableCell = paragraphRange.parentTableCellOrNullObject;
parentCell.load("value");
await context.sync();
if (parentCell.isNullObject) {
console.warn("The first paragraph is not inside a table cell.");
return;
}
console.log(`Parent cell text: ${parentCell.value}`);
});
parentTableOrNullObject
範囲を含むテーブルを取得します。 テーブルに含まれない場合、このメソッドは isNullObject プロパティが true に設定されたオブジェクトを返します。 詳細については、「 *OrNullObject のメソッドとプロパティ」を参照してください。
readonly parentTableOrNullObject: Word.Table;
プロパティ値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/inspect-range-structure.yaml
// Checks whether the first paragraph is inside a table.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange();
const parentTable: Word.Table = paragraphRange.parentTableOrNullObject;
parentTable.load("rowCount");
await context.sync();
if (parentTable.isNullObject) {
console.warn("The first paragraph is not inside a table.");
return;
}
console.log(`Parent table rows: ${parentTable.rowCount}`);
});
revisions
範囲内の変更履歴を表すリビジョンのコレクションを取得します。
readonly revisions: Word.RevisionCollection;
プロパティ値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-tracked-changes.yaml
// Reads revision metadata for the first paragraph on desktop Word.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange();
const revisions: Word.RevisionCollection = paragraphRange.revisions;
revisions.load("items/author,items/date,items/type,items/index,items/formatDescription");
await context.sync();
console.log(`Revisions in the first paragraph: ${revisions.items.length}`);
revisions.items.forEach((revision: Word.Revision) => {
console.log("Revision properties:", {
author: revision.author,
date: revision.date,
type: revision.type,
index: revision.index,
formatDescription: revision.formatDescription,
});
});
});
sections
範囲内のセクションのコレクションを取得します。
readonly sections: Word.SectionCollection;
プロパティ値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/inspect-range-layout-desktop.yaml
// Reads the text of sections intersecting the document body range.
await Word.run(async (context) => {
const bodyRange: Word.Range = context.document.body.getRange();
const sections: Word.SectionCollection = bodyRange.sections;
sections.load("items/body/text");
await context.sync();
console.log(`Sections found: ${sections.items.length}`);
sections.items.forEach((section: Word.Section) => console.log(section.body.text));
});
shading
範囲の網掛け書式を参照する ShadingUniversal オブジェクトを返します。
readonly shading: Word.ShadingUniversal;
プロパティ値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/28-formatting/range-borders-and-shading-desktop.yaml
// Adds a pale blue background to the first paragraph's text.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange(Word.RangeLocation.content);
const shading: Word.ShadingUniversal = paragraphRange.shading;
shading.backgroundPatternColor = "#DDEBF7";
await context.sync();
console.log("Applied pale blue shading.");
});
shapes
範囲に固定されている Shape オブジェクトのコレクション (インライン図形と浮動図形の両方を含む) を取得します。 現時点では、テキスト ボックス、幾何学的図形、グループ、画像、キャンバスの図形のみがサポートされています。
readonly shapes: Word.ShapeCollection;
プロパティ値
注釈
重要: 時間の経過とともに、追加の種類の図形がサポートされる場合があることに注意してください。 そのため、アドインでは特定の種類の図形を要求および処理する必要があります。
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/15-images/insert-and-inspect-floating-pictures-desktop.yaml
// Reads shapes anchored within the first paragraph range.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange();
const shapes: Word.ShapeCollection = paragraphRange.shapes;
shapes.load("items/name,items/type,items/width,items/height");
await context.sync();
console.log(`Shapes anchored in the first paragraph: ${shapes.items.length}`);
shapes.items.forEach((shape: Word.Shape) => {
console.log("Anchored shape:", { name: shape.name, type: shape.type, width: shape.width, height: shape.height });
});
});
showAll
印刷されない文字 (隠しテキスト、タブ記号、スペース記号、段落記号など) をすべて表示するかどうかを指定します。
showAll: boolean;
プロパティ値
boolean
注釈
spellingChecked
範囲またはドキュメント全体でスペル チェックが行われるかどうかを指定します。
spellingChecked: boolean;
プロパティ値
boolean
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/28-formatting/manage-language-and-proofing-desktop.yaml
// Marks the first paragraph as needing another spelling check.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange(Word.RangeLocation.content);
paragraphRange.spellingChecked = false;
await context.sync();
console.log("Reset the English paragraph's spelling-checked flag. Get language and proofing settings to inspect it.");
});
start
範囲の開始文字位置を指定します。
start: number;
プロパティ値
number
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/inspect-and-adjust-range-boundaries-desktop.yaml
// Selects the first paragraph's text except its first character.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange(Word.RangeLocation.content);
paragraphRange.load("start,end");
await context.sync();
if (paragraphRange.start === paragraphRange.end) {
console.warn("The paragraph is empty. Run Set up again.");
return;
}
paragraphRange.start = paragraphRange.start + 1;
paragraphRange.select();
await context.sync();
console.log("Selected the range with its starting position advanced by one character.");
});
storyLength
範囲を含むストーリー内のキャラクターの数を取得します。
readonly storyLength: number;
プロパティ値
number
注釈
storyType
範囲のストーリー タイプを取得します。
readonly storyType: Word.StoryType | "MainText" | "Footnotes" | "Endnotes" | "Comments" | "TextFrame" | "EvenPagesHeader" | "PrimaryHeader" | "EvenPagesFooter" | "PrimaryFooter" | "FirstPageHeader" | "FirstPageFooter" | "FootnoteSeparator" | "FootnoteContinuationSeparator" | "FootnoteContinuationNotice" | "EndnoteSeparator" | "EndnoteContinuationSeparator" | "EndnoteContinuationNotice";
プロパティ値
Word.StoryType | "MainText" | "Footnotes" | "Endnotes" | "Comments" | "TextFrame" | "EvenPagesHeader" | "PrimaryHeader" | "EvenPagesFooter" | "PrimaryFooter" | "FirstPageHeader" | "FirstPageFooter" | "FootnoteSeparator" | "FootnoteContinuationSeparator" | "FootnoteContinuationNotice" | "EndnoteSeparator" | "EndnoteContinuationSeparator" | "EndnoteContinuationNotice"
注釈
style
範囲のスタイル名を指定します。 カスタム スタイルとローカライズされたスタイルの名前には、このプロパティを使用します。 ロケール間で移植可能な組み込みスタイルを使用するには、"styleBuiltIn" プロパティを参照してください。
style: string;
プロパティ値
string
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/basic-range-operations.yaml
// Applies the sample's custom paragraph style to the first paragraph range.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange();
paragraphRange.style = "RangeSampleStyle";
await context.sync();
console.log("Applied the sample's custom style.");
});
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: Word.Range = 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();
});
tableColumns
範囲内のすべてのテーブル列を表す TableColumnCollection オブジェクトを取得します。
readonly tableColumns: Word.TableColumnCollection;
プロパティ値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/40-tables/manage-table-rows-columns-cells.yaml
// Gets properties of the first column in the sample table.
await Word.run(async (context) => {
const firstTable: Word.Table = context.document.body.tables.getFirst();
const tableRange: Word.Range = firstTable.getRange();
const tableColumns: Word.TableColumnCollection = tableRange.tableColumns;
tableColumns.load("items/columnIndex,items/isFirst,items/isLast,items/width");
await context.sync();
const firstColumn: Word.TableColumn = tableColumns.items[0];
console.log(
"First table column:",
`- Index: ${firstColumn.columnIndex}`,
`- Is first: ${firstColumn.isFirst}`,
`- Is last: ${firstColumn.isLast}`,
`- Width: ${firstColumn.width} points`
);
});
tables
範囲内の Table オブジェクトのコレクションを取得します。
readonly tables: Word.TableCollection;
プロパティ値
注釈
text
範囲のテキストを取得します。
readonly text: string;
プロパティ値
string
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/05-coauthoring/get-coauthoring-updates.yaml
// Gets the ranges affected by the most recent coauthoring updates merged into the document.
await Word.run(async (context) => {
const updates: Word.CoauthoringUpdateCollection = context.document.coauthoring.updates;
updates.load("items/range");
await context.sync();
if (updates.items.length === 0) {
console.log("No recent coauthoring updates found.");
return;
}
console.log(`Found ${updates.items.length} recent update(s).`);
const ranges = updates.items.map((u) => u.range);
ranges.forEach((r) => r.load("text"));
await context.sync();
ranges.forEach((range, i) => {
console.log(` Update ${i + 1}: "${range.text}"`);
});
});
twoLinesInOne
Microsoft Word が 2 行のテキストを 1 つに設定するかどうか、およびテキストを囲む文字を指定する (存在する場合)。
twoLinesInOne: Word.TwoLinesInOneType | "None" | "NoBrackets" | "Parentheses" | "SquareBrackets" | "AngleBrackets" | "CurlyBrackets";
プロパティ値
Word.TwoLinesInOneType | "None" | "NoBrackets" | "Parentheses" | "SquareBrackets" | "AngleBrackets" | "CurlyBrackets"
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/28-formatting/apply-character-layout-desktop.yaml
// Displays the first paragraph's text as two lines enclosed in parentheses.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange(Word.RangeLocation.content);
const twoLineLayout: Word.TwoLinesInOneType = Word.TwoLinesInOneType.parentheses;
paragraphRange.twoLinesInOne = twoLineLayout;
await context.sync();
console.log("Applied two-line text with parentheses to the first paragraph.");
});
underline
注意
この API は開発者向けにプレビューとして提供されており、寄せられたフィードバックにもとづいて変更される場合があります。 この API は運用環境で使用しないでください。
範囲に適用される下線の種類を指定します。
readonly underline: Word.UnderlineType | "Mixed" | "None" | "Hidden" | "DotLine" | "Single" | "Word" | "Double" | "Thick" | "Dotted" | "DottedHeavy" | "DashLine" | "DashLineHeavy" | "DashLineLong" | "DashLineLongHeavy" | "DotDashLine" | "DotDashLineHeavy" | "TwoDotDashLine" | "TwoDotDashLineHeavy" | "Wave" | "WaveHeavy" | "WaveDouble";
プロパティ値
Word.UnderlineType | "Mixed" | "None" | "Hidden" | "DotLine" | "Single" | "Word" | "Double" | "Thick" | "Dotted" | "DottedHeavy" | "DashLine" | "DashLineHeavy" | "DashLineLong" | "DashLineLongHeavy" | "DotDashLine" | "DotDashLineHeavy" | "TwoDotDashLine" | "TwoDotDashLineHeavy" | "Wave" | "WaveHeavy" | "WaveDouble"
注釈
API セット: WordApi ベータ版 (プレビューのみ)
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/99-preview-apis/read-range-underline.yaml
// Reads the underline applied to the first paragraph range.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange(Word.RangeLocation.content);
paragraphRange.load("underline");
await context.sync();
const singleUnderline: Word.UnderlineType = Word.UnderlineType.single;
console.log(`Underline type: ${paragraphRange.underline}`);
console.log(`Has a single underline: ${paragraphRange.underline === singleUnderline}`);
});
メソッドの詳細
clear()
Range オブジェクトの内容をクリアします。 ユーザーは、消去された内容を元に戻す操作を実行できます。
clear(): void;
戻り値
void
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/basic-range-operations.yaml
// Removes the first paragraph's text while preserving the paragraph.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange(Word.RangeLocation.content);
paragraphRange.clear();
await context.sync();
console.log("Cleared the summary text. The paragraph remains.");
});
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: Word.ParagraphCollection = context.document.body.paragraphs;
paragraphs.load("items");
await context.sync();
const firstParagraphAsRange: Word.Range = paragraphs.items[0].getRange();
const secondParagraphAsRange: Word.Range = paragraphs.items[1].getRange();
const comparedLocation: OfficeExtension.ClientResult<Word.LocationRelation> =
firstParagraphAsRange.compareLocationWith(secondParagraphAsRange);
await context.sync();
const locationValue: Word.LocationRelation = comparedLocation.value;
console.log(`Location of the first paragraph in relation to the second paragraph: ${locationValue}`);
});
delete()
文書から範囲と、その範囲の内容を削除します。
delete(): void;
戻り値
void
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/basic-range-operations.yaml
// Deletes the first paragraph range, including its paragraph mark.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange();
paragraphRange.delete();
await context.sync();
console.log("Deleted the first paragraph range.");
});
detectLanguage()
範囲テキストを分析して、記述されている言語を決定します。
detectLanguage(): OfficeExtension.ClientResult<boolean>;
戻り値
OfficeExtension.ClientResult<boolean>
注釈
expandTo(range)
別の範囲を対象にするために、いずれかの方向でこの範囲から拡張する新しい範囲を返します。 この範囲は変更されません。 2 つの範囲に和集合がない場合は、 ItemNotFound エラーをスローします。
expandTo(range: Word.Range): Word.Range;
パラメーター
- range
- Word.Range
もう 1 つの範囲。
戻り値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/compare-location.yaml
// Gets the text spanning the first two paragraphs.
await Word.run(async (context) => {
const firstRange: Word.Range = context.document.body.paragraphs.getFirst().getRange();
const secondRange: Word.Range = context.document.body.paragraphs.getFirst().getNext().getRange();
const expandedRange: Word.Range = firstRange.expandTo(secondRange);
expandedRange.load("text");
await context.sync();
console.log(`Expanded text: ${expandedRange.text}`);
});
expandToOrNullObject(range)
別の範囲を対象にするために、いずれかの方向でこの範囲から拡張する新しい範囲を返します。 この範囲は変更されません。 2 つの範囲に和集合がない場合、このメソッドは isNullObject プロパティが true に設定されたオブジェクトを返します。 詳細については、「 *OrNullObject のメソッドとプロパティ」を参照してください。
expandToOrNullObject(range: Word.Range): Word.Range;
パラメーター
- range
- Word.Range
もう 1 つの範囲。
戻り値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/compare-location.yaml
// Expands to the selection when both ranges belong to the same story.
await Word.run(async (context) => {
const firstRange: Word.Range = context.document.body.paragraphs.getFirst().getRange();
const selection: Word.Range = context.document.getSelection();
const expandedRange: Word.Range = firstRange.expandToOrNullObject(selection);
expandedRange.load("text");
await context.sync();
if (expandedRange.isNullObject) {
console.warn("The ranges cannot be combined. Select text in the main document body.");
return;
}
console.log(`Expanded text: ${expandedRange.text}`);
});
getBookmarks(includeHidden, includeAdjacent)
範囲内または範囲内に重なるすべてのブックマークの名前を取得します。 ブックマークは、名前がアンダースコア文字で始まる場合、非表示になります。
getBookmarks(includeHidden?: boolean, includeAdjacent?: boolean): OfficeExtension.ClientResult<string[]>;
パラメーター
- includeHidden
-
boolean
省略可能。 非表示のブックマークを含めるかどうかを指定します。 既定値は false です。これは非表示のブックマークが除外されることを示します。
- includeAdjacent
-
boolean
省略可能。 範囲に隣接するブックマークを含めるかどうかを示します。 既定値は false で、隣接するブックマークが除外されることを示します。
戻り値
OfficeExtension.ClientResult<string[]>
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/manage-range-bookmarks.yaml
// Gets the names of bookmarks within or overlapping the first paragraph.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange();
const bookmarkNames: OfficeExtension.ClientResult<string[]> = paragraphRange.getBookmarks(false, true);
await context.sync();
console.log("Bookmark names:", bookmarkNames.value);
});
getComments()
範囲に関連付けられているコメントを取得します。
getComments(): Word.CommentCollection;
戻り値
範囲に関連付けられているすべてのコメントを含む 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: Word.Range = context.document.getSelection();
let selectedContentControl = selectedRange
.getContentControls({
types: [Word.ContentControlType.checkBox]
})
.getFirstOrNullObject();
selectedContentControl.load("id");
await context.sync();
if (selectedContentControl.isNullObject) {
const parentContentControl: Word.ContentControl = 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()
Range オブジェクトの HTML 表現を取得します。 Web ページまたは HTML ビューアーで表示すると、書式設定はドキュメントの書式設定とほぼ一致しますが、完全一致ではありません。 このメソッドでは、異なるプラットフォーム (Windows、Mac、Web 上の Word など) 上の同じドキュメントに対してまったく同じ HTML は返されません。 プラットフォーム間で正確な忠実性や一貫性が必要な場合は、 Range.getOoxml() を使用して返される XML を HTML に変換します。
getHtml(): OfficeExtension.ClientResult<string>;
戻り値
OfficeExtension.ClientResult<string>
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/insert-and-read-formatted-content.yaml
// Reads an HTML representation of the first paragraph range.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange();
const html: OfficeExtension.ClientResult<string> = paragraphRange.getHtml();
await context.sync();
console.log(`Range HTML: ${html.value}`);
});
getHyperlinkRanges()
範囲内のハイパーリンクの子の範囲を取得します。
getHyperlinkRanges(): Word.RangeCollection;
戻り値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/inspect-range-structure.yaml
// Reads the text and destinations of hyperlinks in the document body range.
await Word.run(async (context) => {
const bodyRange: Word.Range = context.document.body.getRange();
const hyperlinkRanges: Word.RangeCollection = bodyRange.getHyperlinkRanges();
hyperlinkRanges.load("items/text,items/hyperlink");
await context.sync();
console.log(`Hyperlinks found: ${hyperlinkRanges.items.length}`);
hyperlinkRanges.items.forEach((hyperlinkRange: Word.Range) => {
console.log({ text: hyperlinkRange.text, hyperlink: hyperlinkRange.hyperlink });
});
});
getNextTextRange(endingMarks, trimSpacing)
句読点やその他の終了記号を使用して、次のテキスト範囲を取得します。 このテキスト範囲が最後のテキスト範囲である場合は、 ItemNotFound エラーをスローします。
getNextTextRange(endingMarks: string[], trimSpacing?: boolean): Word.Range;
パラメーター
- endingMarks
-
string[]
句読点とその他の終了記号は文字列の配列です。
- trimSpacing
-
boolean
省略可能。 返される範囲の開始と終了からスペース文字 (スペース、タブ、列区切り、段落終了記号) をトリミングするかどうかを示します。 既定値は false です。これは、範囲の先頭と末尾のスペース文字が含まれます。
戻り値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/split-words-of-first-paragraph.yaml
// Gets the sentence following the first sentence in the document.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange();
const firstSentence: Word.Range = paragraphRange.getTextRanges(["?", "."], true).getFirst();
const nextSentence: Word.Range = firstSentence.getNextTextRange(["?", "."], true);
nextSentence.load("text");
await context.sync();
console.log(`Next sentence: ${nextSentence.text}`);
});
getNextTextRangeOrNullObject(endingMarks, trimSpacing)
句読点やその他の終了記号を使用して、次のテキスト範囲を取得します。 このテキスト範囲が最後のテキスト範囲である場合、このメソッドは、 isNullObject プロパティが true に設定されたオブジェクトを返します。 詳細については、「 *OrNullObject のメソッドとプロパティ」を参照してください。
getNextTextRangeOrNullObject(endingMarks: string[], trimSpacing?: boolean): Word.Range;
パラメーター
- endingMarks
-
string[]
句読点とその他の終了記号は文字列の配列です。
- trimSpacing
-
boolean
省略可能。 返される範囲の開始と終了からスペース文字 (スペース、タブ、列区切り、段落終了記号) をトリミングするかどうかを示します。 既定値は false です。これは、範囲の先頭と末尾のスペース文字が含まれます。
戻り値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/split-words-of-first-paragraph.yaml
// Checks for a sentence after the end of the document without throwing.
await Word.run(async (context) => {
const endRange: Word.Range = context.document.body.getRange(Word.RangeLocation.end);
const nextSentence: Word.Range = endRange.getNextTextRangeOrNullObject([".", "?"], true);
nextSentence.load("text");
await context.sync();
if (nextSentence.isNullObject) {
console.warn("There is no sentence after the end of the document.");
return;
}
console.log(`Next sentence: ${nextSentence.text}`);
});
getOoxml()
Range オブジェクトの OOXML 表現を取得します。
getOoxml(): OfficeExtension.ClientResult<string>;
戻り値
OfficeExtension.ClientResult<string>
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/insert-and-read-formatted-content.yaml
// Reads the OOXML representation of the first paragraph range.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange();
const ooxml: OfficeExtension.ClientResult<string> = paragraphRange.getOoxml();
await context.sync();
console.log(`Range OOXML: ${ooxml.value}`);
});
getRange(rangeLocation)
Range オブジェクトを複製するか、範囲の開始点または終了点を新しい範囲として取得します。
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 である必要があります。
戻り値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/10-content-controls/insert-and-change-dropdown-list-content-control.yaml
// Places a dropdown list content control at the end of the selection.
await Word.run(async (context) => {
let selection = context.document.getSelection();
selection.getRange(Word.RangeLocation.end).insertContentControl(Word.ContentControlType.dropDownList);
await context.sync();
console.log("Dropdown list content control inserted at the end of the selection.");
});
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: Word.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(changeTrackingVersion)
ChangeTrackingVersion の選択に基づいてレビューされたテキストを取得します。
getReviewedText(changeTrackingVersion?: "Original" | "Current"): OfficeExtension.ClientResult<string>;
パラメーター
- changeTrackingVersion
-
"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
// Gets complete sentences from the insertion point to the end of its paragraph.
await Word.run(async (context) => {
const selection: Word.Range = context.document.getSelection();
const sentences: Word.RangeCollection = selection.getTextRanges(["."], false);
sentences.load("$none");
await context.sync();
const firstSentence: Word.Range = sentences.items[0];
const paragraphEnd: Word.Range = selection.paragraphs.getFirst().getRange(Word.RangeLocation.end);
const remainingRange: Word.Range = firstSentence.expandTo(paragraphEnd);
const sentencesToTheEndOfParagraph: Word.RangeCollection = remainingRange.getTextRanges(["."], false);
sentencesToTheEndOfParagraph.load("text");
await context.sync();
console.log("Sentences from the current sentence to the paragraph end:");
for (let i = 0; i < sentencesToTheEndOfParagraph.items.length; i++) {
console.log(sentencesToTheEndOfParagraph.items[i].text);
}
});
getTrackedChanges()
範囲内の TrackedChange オブジェクトのコレクションを取得します。
getTrackedChanges(): Word.TrackedChangeCollection;
戻り値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-tracked-changes.yaml
// Gets the tracked changes inside the first paragraph.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange();
const trackedChanges: Word.TrackedChangeCollection = paragraphRange.getTrackedChanges();
trackedChanges.load("items/author,items/text,items/type");
await context.sync();
console.log(`Tracked changes in the first paragraph: ${trackedChanges.items.length}`);
trackedChanges.items.forEach((change: Word.TrackedChange) => {
console.log({ author: change.author, text: change.text, type: change.type });
});
});
highlight()
ドキュメントの内容を変更せずに範囲を一時的に強調表示します。 テキストを永続的に強調表示するには、範囲の font.highlightColorを設定します。
highlight(): void;
戻り値
void
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/scroll-to-range.yaml
// Temporarily highlights the final paragraph without changing its formatting.
await Word.run(async (context) => {
const lastRange: Word.Range = context.document.body.paragraphs.getLast().getRange();
lastRange.highlight();
await context.sync();
console.log("Temporarily highlighted the final paragraph.");
});
insertBookmark(name)
範囲にブックマークを挿入します。 同じ名前のブックマークがどこかに存在する場合は、最初に削除されます。
insertBookmark(name: string): void;
パラメーター
- name
-
string
大文字と小文字を区別しないブックマーク名。 英数字とアンダースコア文字のみがサポートされています。 先頭は文字で始まる必要がありますが、ブックマークに非表示のタグを付ける場合は、名前にアンダースコア文字を付けます。 名前は 40 文字以内でなければなりません。
戻り値
void
注釈
注: ブックマークを挿入する条件は、Word UI で挿入する条件と似ています。 Word UI でのブックマークの管理の詳細については、「Word ドキュメントまたは Outlook メッセージのブックマークを追加または削除する」を参照してください。
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/manage-range-bookmarks.yaml
// Names the first paragraph range, replacing any existing bookmark with this name.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange(Word.RangeLocation.content);
paragraphRange.insertBookmark("RangeSampleSummary");
await context.sync();
console.log("Inserted the RangeSampleSummary bookmark. Get bookmark names to verify it.");
});
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
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/basic-range-operations.yaml
// Inserts a page break after the first paragraph range.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange();
paragraphRange.insertBreak(Word.BreakType.page, Word.InsertLocation.after);
await context.sync();
console.log("Inserted a page break after the summary.");
});
insertCanvas(insertShapeOptions)
テキストの前にフローティング キャンバスを挿入し、アンカーを範囲の先頭に配置します。
insertCanvas(insertShapeOptions?: Word.InsertShapeOptions): Word.Shape;
パラメーター
- insertShapeOptions
- Word.InsertShapeOptions
省略可能。 キャンバスの位置とサイズ。 既定の場所とサイズは (0, 0, 300, 200) です。
戻り値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/45-shapes/manage-canvases.yaml
await Word.run(async (context) => {
// Inserts a canvas in the document.
const canvasShape: Word.Shape = context.document.getSelection().insertCanvas();
canvasShape.load();
await context.sync();
canvasShape.select();
console.log("Inserted canvas:", canvasShape);
const canvas: Word.Canvas = canvasShape.canvas;
canvas.load("shape,shapes");
await context.sync();
console.log("Canvas object:", canvas);
});
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 = (document.getElementById("comment-text") as HTMLInputElement).value;
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 | 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
、plainText、checkBox、dropDownList、comboBox、buildingBlockGallery、datePicker、repeatingSection、picture、または group である必要があります。 既定値は richText です。
戻り値
注釈
注: contentControlType パラメーターは WordApi 1.5 で導入されました。
plainText サポートは WordApi 1.5 で追加されました。
checkBox サポートは WordApi 1.7 で追加されました。
dropDownList
comboBoxサポートは WordApi 1.9 で追加されました。
buildingBlockGallery
、datePicker、group、picture、repeatingSection のサポートは、WordApiDesktop 1.3 で追加されました。
例
// 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: Word.RangeCollection = context.document.body.search("Contractor");
results.load("font/bold");
// Check to make sure these content controls haven't been added yet.
const customerContentControls: Word.ContentControlCollection = 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: Word.ContentControl = 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
省略可能。 文末脚注本文に挿入するテキスト。 既定値は "" です。
戻り値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/manage-footnotes.yaml
// Adds an endnote to the first paragraph.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange();
const endnote: Word.NoteItem = paragraphRange.insertEndnote("Source: the sample document.");
await context.sync();
console.log("Inserted an endnote. Its text appears at the end of the document.");
});
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 値を指定できます。 既定値は empty です。
- text
-
string
省略可能。 指定したフィールド型に必要な追加のプロパティまたはオプション。
- removeFormatting
-
boolean
省略可能。
true 更新中にフィールドに適用されている書式設定を削除するには、それ以外の false を行います。 既定値は false です。
戻り値
注釈
重要: Windows と Mac の Word では、API は Word にリストされているすべての種類の挿入と管理をサポートしています。Word.FieldType.othersを除く FieldType。 Word on the web では、フィールドは主に読み取り専用です。 詳細については、「Word アドインでフィールドを使用する」を参照してください。
例
// 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: Word.Range = context.document.getSelection().getRange();
const field: Word.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, fieldType, text, removeFormatting)
指定した場所にフィールドを挿入します。
insertField(insertLocation: Word.InsertLocation | "Replace" | "Start" | "End" | "Before" | "After", fieldType?: "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 である必要があります。
- fieldType
-
"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 値を指定できます。 既定値は empty です。
- text
-
string
省略可能。 指定したフィールド型に必要な追加のプロパティまたはオプション。
- removeFormatting
-
boolean
省略可能。
true 更新中にフィールドに適用されている書式設定を削除するには、それ以外の false を行います。 既定値は false です。
戻り値
注釈
重要: Windows と Mac の Word では、API は Word にリストされているすべての種類の挿入と管理をサポートしています。Word.FieldType.othersを除く FieldType。 Word on the web では、フィールドは主に読み取り専用です。 詳細については、「Word アドインでフィールドを使用する」を参照してください。
insertFileFromBase64(base64File, insertLocation)
指定した位置に文書を挿入します。 挿入する文書の最大サイズは 4 MB です。
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 コントロール (フォーム フィールドにある可能性があります) が含まれている場合、挿入はサポートされません。 このようなフォーム フィールドを、シナリオに適したコンテンツ コントロールまたはその他のオプションに置き換えることを検討してください。
挿入するドキュメントにリンクされたコンテンツまたは外部コンテンツが含まれている場合、挿入はサポートされません。 その場合、このメソッドは InvalidArgument エラーを返します。
ドキュメントを挿入するときに、ドキュメントの設定は保持されません。
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/insert-and-read-formatted-content.yaml
// Replaces the first paragraph with the contents of a small embedded DOCX file.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange();
// The DOCX contains one paragraph: "Imported project update."
const base64File: string = "UEsDBBQAAAAIAAAAIVD3S4B1wgAAAHYBAAATAAAAW0NvbnRlbnRfVHlwZXNdLnhtbH2QuQ7CMAyGX6XKiqgRAwOiLMAKDLyAlbptRC7FLsfbk3INCBjt//gsLw7XSFxcnPVcqU4kzgFYd+SQyxDJZ6UJyaHkMbUQUR+xJZhOJjPQwQt5GcvQoZaLNTXYWyk2l7xmE3ylEllWxephHFiVwhit0ShZh5OvPyjjJ6HMybuHOxN5lA0KvhIG5TfgmdudKCVTU7HHJFt02QXnkGqog+5dTpb/a77cGZrGaHrnh7aYgiZm41tny7fi0PjX/XB/9/IGUEsDBBQAAAAIAAAAIVBhey9DiQAAAPIAAAALAAAAX3JlbHMvLnJlbHONzzsOAiEQBuCrEA6ws1pYGKCy2dZ4AQLDIy6PDBj19lJYrMbCcuaffH9GnHHVPZbcQqyNPdKam+Sh93oEaCZg0m0qFfNIXKGk+xjJQ9Xmqj3Cfp4PQFuDK7E12WIlp8XuOLs8K/5jF+eiwVMxt4S5/6j4uhiyJo9d8nshC/a9ngbLQQn4eFG9AFBLAwQUAAAACAAAACFQZhg8uIUAAAC1AAAAEQAAAHdvcmQvZG9jdW1lbnQueG1sRY47DsIwDIavUvUAdcXAEIXubFwhJKYtquPIcZVye5IysHyW/T9kW0xgvxNG7Q7aYjbl1i+qyQBkvyC5PHDCWLUXCzmtq8xQWEIS9pjzGmfa4DKOVyC3xn6yxTw5fNpMDdKg050Si2Loau6NXrs9Bac4WGhqo5w8M7kaHgLn4VcG/0enL1BLAQIUABQAAAAIAAAAIVD3S4B1wgAAAHYBAAATAAAAAAAAAAAAAACAAQAAAABbQ29udGVudF9UeXBlc10ueG1sUEsBAhQAFAAAAAgAAAAhUGF7L0OJAAAA8gAAAAsAAAAAAAAAAAAAAIAB8wAAAF9yZWxzLy5yZWxzUEsBAhQAFAAAAAgAAAAhUGYYPLiFAAAAtQAAABEAAAAAAAAAAAAAAIABpQEAAHdvcmQvZG9jdW1lbnQueG1sUEsFBgAAAAADAAMAuQAAAFkCAAAAAA==";
const insertedRange: Word.Range = paragraphRange.insertFileFromBase64(base64File, Word.InsertLocation.replace);
await context.sync();
console.log("Inserted the embedded document's project update.");
});
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 = (document.getElementById("input-footnote") as HTMLInputElement).value;
const footnote: Word.NoteItem = context.document.getSelection().insertFootnote(text);
await context.sync();
console.log("Inserted footnote.");
});
insertGeometricShape(geometricShapeType, insertShapeOptions)
テキストの前に幾何学図形を挿入し、範囲の先頭にアンカーを配置します。
insertGeometricShape(geometricShapeType: Word.GeometricShapeType, insertShapeOptions?: Word.InsertShapeOptions): Word.Shape;
パラメーター
- geometricShapeType
- Word.GeometricShapeType
挿入する図形の幾何学的タイプ。
- insertShapeOptions
- Word.InsertShapeOptions
省略可能。 幾何学的図形の位置とサイズ。 既定の場所とサイズは (0, 0, 100, 100) です。
戻り値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/45-shapes/manage-geometric-shapes.yaml
await Word.run(async (context) => {
// Inserts a moon geometric shape at the beginning of the selection.
const selection: Word.Range = context.document.getSelection();
const shapeOptions: Word.InsertShapeOptions = {
height: 120,
width: 120,
left: 120,
};
selection.insertGeometricShape(Word.GeometricShapeType.moon, shapeOptions);
await context.sync();
console.log("Inserted a moon.");
});
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) です。
戻り値
注釈
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 である必要があります。
戻り値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/insert-and-read-formatted-content.yaml
// Replaces the first paragraph's content with formatted HTML.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange(Word.RangeLocation.content);
const insertedRange: Word.Range = paragraphRange.insertHtml("<b>Project update:</b> <i>ready for review.</i>", Word.InsertLocation.replace);
await context.sync();
console.log("Inserted bold and italic text from HTML.");
});
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 である必要があります。
戻り値
注釈
例
// 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 picture at the start of the first text box.
const firstShapeWithTextBox: Word.Shape = context.document.body.shapes
.getByTypes([Word.ShapeType.textBox])
.getFirst();
firstShapeWithTextBox.load("type/body");
await context.sync();
const startRange: Word.Range = firstShapeWithTextBox.body.getRange(Word.RangeLocation.start);
const newPic: Word.InlinePicture = startRange.insertInlinePictureFromBase64(
getPictureBase64(),
Word.InsertLocation.start
);
newPic.load();
await context.sync();
console.log("New inline picture properties:", newPic);
});
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 である必要があります。
戻り値
注釈
挿入されるコンテンツにリンクされたコンテンツまたは外部コンテンツが含まれている場合、挿入はサポートされません。 その場合、このメソッドは InvalidArgument エラーを返します。
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/insert-and-read-formatted-content.yaml
// Replaces the first paragraph with a bold paragraph from an OOXML package.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange();
const ooxml: string =
`<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: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:r><w:rPr><w:b/></w:rPr><w:t>Project update from OOXML.</w:t></w:r></w:p></w:body>
</w:document></pkg:xmlData>
</pkg:part>
</pkg:package>`;
const insertedRange: Word.Range = paragraphRange.insertOoxml(ooxml, Word.InsertLocation.replace);
await context.sync();
console.log("Inserted a bold paragraph from OOXML.");
});
insertParagraph(paragraphText, insertLocation)
指定した位置に、段落を挿入します。
insertParagraph(paragraphText: string, insertLocation: Word.InsertLocation.before | Word.InsertLocation.after | "Before" | "After"): Word.Paragraph;
パラメーター
- paragraphText
-
string
挿入する段落テキスト。
戻り値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/basic-range-operations.yaml
// Adds a paragraph after the first paragraph range.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange();
const newParagraph: Word.Paragraph = paragraphRange.insertParagraph("Additional project details.", Word.InsertLocation.after);
await context.sync();
console.log("Inserted a paragraph after the summary.");
});
insertPictureFromBase64(base64EncodedImage, insertShapeOptions)
テキストの前に浮動ピクチャを挿入し、範囲の先頭にアンカーを配置します。
insertPictureFromBase64(base64EncodedImage: string, insertShapeOptions?: Word.InsertShapeOptions): Word.Shape;
パラメーター
- base64EncodedImage
-
string
挿入する Base64 でエンコードされた画像。
- insertShapeOptions
- Word.InsertShapeOptions
省略可能。 画像の場所とサイズ。 既定の場所は (0, 0) で、既定のサイズは画像の元のサイズです。
戻り値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/15-images/insert-and-inspect-floating-pictures-desktop.yaml
// Anchors a floating picture at the start of the first paragraph.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange();
const pictureOptions: Word.InsertShapeOptions = { left: 20, top: 20, width: 90, height: 39 };
const picture: Word.Shape = paragraphRange.insertPictureFromBase64(
"iVBORw0KGgoAAAANSUhEUgAAAB4AAAANCAIAAAAxEEnAAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACFSURBVDhPtY1BEoQwDMP6/0+XgIMTBAeYoTqso9Rkx1zG+tNj1H94jgGzeNSjteO5vtQQuG2seO0av8LzGbe3anzRoJ4ybm/VeKEerAEbAUpW4aWQCmrGFWykRzGBCnYy2ha3oAIq2MloW9yCCqhgJ6NtcQsqoIKdjLbFLaiACnYyf2fODbrjZcXfr2F4AAAAAElFTkSuQmCC",
pictureOptions
);
picture.name = "FloatingPictureSample";
await context.sync();
console.log("Inserted a floating picture anchored to the first paragraph. Get anchored shapes to inspect it.");
});
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 次元配列。 対応する文字列が配列で指定されている場合、セルに設定されます。
戻り値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/inspect-range-structure.yaml
// Adds a project status table after the last paragraph range.
await Word.run(async (context) => {
const lastRange: Word.Range = context.document.body.paragraphs.getLast().getRange();
const projectTable: Word.Table = lastRange.insertTable(2, 2, Word.InsertLocation.after, [
["Task", "Status"],
["Review", "Ready"]
]);
await context.sync();
console.log("Inserted a project status table.");
});
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 である必要があります。
戻り値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/basic-range-operations.yaml
// Replaces the first paragraph's text without replacing its paragraph mark.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange(Word.RangeLocation.content);
const insertedRange: Word.Range = paragraphRange.insertText("Updated project summary.", Word.InsertLocation.replace);
await context.sync();
console.log("Replaced the first paragraph's text.");
});
insertTextBox(text, insertShapeOptions)
テキストの前にフローティング テキスト ボックスを挿入し、アンカーを範囲の先頭に配置します。
insertTextBox(text?: string, insertShapeOptions?: Word.InsertShapeOptions): Word.Shape;
パラメーター
- text
-
string
省略可能。 テキスト ボックスに挿入するテキスト。
- insertShapeOptions
- Word.InsertShapeOptions
省略可能。 テキスト ボックスの場所とサイズ。 既定の場所とサイズは (0, 0, 100, 100) です。
戻り値
注釈
例
// 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 selection.
const range: Word.Range = context.document.getSelection();
const insertShapeOptions: Word.InsertShapeOptions = {
top: 0,
left: 0,
height: 100,
width: 100
};
const newTextBox: Word.Shape = range.insertTextBox("placeholder text", insertShapeOptions);
await context.sync();
console.log("Inserted a text box at the beginning of the current selection.");
});
intersectWith(range)
別の範囲とこの範囲の交点として、新しい範囲を返します。 この範囲は変更されません。 2 つの範囲が重なっていない、または隣接していない場合は、 ItemNotFound エラーをスローします。
intersectWith(range: Word.Range): Word.Range;
パラメーター
- range
- Word.Range
もう 1 つの範囲。
戻り値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/compare-location.yaml
// Gets the overlap between the document body and its first paragraph.
await Word.run(async (context) => {
const bodyRange: Word.Range = context.document.body.getRange();
const firstRange: Word.Range = context.document.body.paragraphs.getFirst().getRange();
const overlap: Word.Range = bodyRange.intersectWith(firstRange);
overlap.load("text");
await context.sync();
console.log(`Overlapping text: ${overlap.text}`);
});
intersectWithOrNullObject(range)
別の範囲とこの範囲の交点として、新しい範囲を返します。 この範囲は変更されません。 2 つの範囲が重複または隣接していない場合、このメソッドは isNullObject プロパティが true に設定されたオブジェクトを返します。 詳細については、「 *OrNullObject のメソッドとプロパティ」を参照してください。
intersectWithOrNullObject(range: Word.Range): Word.Range;
パラメーター
- range
- Word.Range
もう 1 つの範囲。
戻り値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/compare-location.yaml
// Checks whether the selection overlaps the first paragraph.
await Word.run(async (context) => {
const firstRange: Word.Range = context.document.body.paragraphs.getFirst().getRange();
const selection: Word.Range = context.document.getSelection();
const overlap: Word.Range = firstRange.intersectWithOrNullObject(selection);
overlap.load("text");
await context.sync();
if (overlap.isNullObject) {
console.warn("The selection does not overlap or adjoin the first paragraph.");
return;
}
console.log(`Overlapping text: ${overlap.text}`);
});
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 は読み込むナビゲーションのプロパティを指定するコンマ区切りの文字列です。
戻り値
removeHighlight()
highlight メソッドによって追加された強調表示がある場合は、削除します。
removeHighlight(): void;
戻り値
void
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/scroll-to-range.yaml
// Removes the temporary highlight from the final paragraph.
await Word.run(async (context) => {
const lastRange: Word.Range = context.document.body.paragraphs.getLast().getRange();
lastRange.removeHighlight();
await context.sync();
console.log("Removed the temporary highlight.");
});
search(searchText, searchOptions)
Range オブジェクトのスコープに対して、指定された検索オプションを使用して検索を実行します。 検索結果は、 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; }
省略可能。 検索のオプション。
戻り値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/basic-range-operations.yaml
// Finds whole-word matches within the first paragraph.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange();
const searchOptions: Word.SearchOptions = Word.SearchOptions.newObject(context);
searchOptions.matchCase = false;
searchOptions.matchWholeWord = true;
const matches: Word.RangeCollection = paragraphRange.search("project", searchOptions);
matches.load("items/text");
await context.sync();
console.log(`Matches found: ${matches.items.length}`);
matches.items.forEach((match: Word.Range) => console.log(match.text));
});
select(selectionMode)
範囲を選択して、その範囲に Word の UI を移動します。
select(selectionMode?: Word.SelectionMode): void;
パラメーター
- selectionMode
- Word.SelectionMode
省略可能。 選択モードは、 select、 start、または end である必要があります。
select が既定です。
戻り値
void
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/scroll-to-range.yaml
// Selects the final paragraph and scrolls it into view.
await Word.run(async (context) => {
const lastRange: Word.Range = context.document.body.paragraphs.getLast().getRange();
lastRange.select();
await context.sync();
});
select(selectionMode)
範囲を選択して、その範囲に Word の UI を移動します。
select(selectionMode?: "Select" | "Start" | "End"): void;
パラメーター
- selectionMode
-
"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
プロパティ オブジェクトが読み取り専用プロパティを設定しようとした場合にエラーを抑制するオプションを提供します。
戻り値
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 です。これは、範囲の先頭と末尾のスペース文字が範囲コレクションに含まれることを示します。
戻り値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/split-words-of-first-paragraph.yaml
// Splits the first paragraph into words and highlights them in sequence.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange();
const words: Word.RangeCollection = paragraphRange.split([" "], false, true, true);
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 new Promise((resolve) => setTimeout(resolve, 200));
}
});
toJSON()
API オブジェクトが JSON.stringify() に渡されるときに、より有用な出力を提供するために、JavaScript toJSON() メソッドをオーバーライドします。 (次に、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;
戻り値
イベントの詳細
onCommentAdded
注意
この API は開発者向けにプレビューとして提供されており、寄せられたフィードバックにもとづいて変更される場合があります。 この API は運用環境で使用しないでください。
新しいコメントが追加されたときに発生します。
readonly onCommentAdded: OfficeExtension.EventHandlers<Word.CommentEventArgs>;
イベントの種類
注釈
onCommentChanged
注意
この API は開発者向けにプレビューとして提供されており、寄せられたフィードバックにもとづいて変更される場合があります。 この API は運用環境で使用しないでください。
コメントまたはその応答が変更されたときに発生します。
readonly onCommentChanged: OfficeExtension.EventHandlers<Word.CommentEventArgs>;
イベントの種類
注釈
onCommentDeselected
注意
この API は開発者向けにプレビューとして提供されており、寄せられたフィードバックにもとづいて変更される場合があります。 この API は運用環境で使用しないでください。
コメントの選択が解除されたときに発生します。
readonly onCommentDeselected: OfficeExtension.EventHandlers<Word.CommentEventArgs>;
イベントの種類
注釈
onCommentSelected
注意
この API は開発者向けにプレビューとして提供されており、寄せられたフィードバックにもとづいて変更される場合があります。 この API は運用環境で使用しないでください。
コメントが選択されているときに発生します。
readonly onCommentSelected: OfficeExtension.EventHandlers<Word.CommentEventArgs>;