Word.Bookmark class
文書内のブックマーク、選択範囲、または指定範囲を表します。
Bookmark オブジェクトは、Bookmark コレクションのメンバーです。 The Word.BookmarkCollection には、[ブックマーク] ダイアログ ボックス ([挿入] メニュー) に一覧表示されているすべてのブックマークが含まれます。
- Extends
注釈
使用元
例
// 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
});
});
});
プロパティ
| context | オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。 |
| end | ブックマークの文字の終了位置を指定します。 |
| is |
ブックマークがテーブル列の場合に |
| is |
ブックマークが空の場合は |
| name |
|
| range |
|
| start | ブックマークの開始文字位置を指定します。 |
| story |
ブックマークのストーリー タイプを返します。 |
メソッド
| copy |
このブックマークを、 |
| delete() | ブックマークを削除します。 |
| load(options) | オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、 |
| load(property |
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、 |
| load(property |
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、 |
| select() | ブックマークを選択します。 |
| set(properties, options) | オブジェクトの複数のプロパティを同時に設定します。 適切なプロパティを持つプレーン オブジェクト、または同じ型の別の API オブジェクトを渡すことができます。 |
| set(properties) | 既存の読み込まれたオブジェクトに基づいて、オブジェクトに複数のプロパティを同時に設定します。 |
| toJSON() | API オブジェクトが |
| track() | ドキュメントの環境変更に基づいて自動的に調整する目的でオブジェクトを追跡します。 この呼び出しは、 context.trackedObjects.add(thisObject) の短縮形です。 このオブジェクトを |
| untrack() | 前に追跡されていた場合、このオブジェクトに関連付けられているメモリを解放します。 この呼び出しは、 context.trackedObjects.remove(thisObject) の省略形です。 追跡対象オブジェクトが多いとホスト アプリケーションの動作が遅くなります。追加したオブジェクトが不要になったら、必ずそれを解放してください。 メモリ リリースを有効にする前に、 |
プロパティの詳細
context
オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。
context: RequestContext;
プロパティ値
end
ブックマークの文字の終了位置を指定します。
end: number;
プロパティ値
number
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/manage-range-bookmarks.yaml
// Move the bookmark's end before the summary's final period.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange(Word.RangeLocation.content);
const bookmarks: Word.BookmarkCollection = paragraphRange.bookmarks;
bookmarks.load("items/name,items/start");
paragraphRange.load("end");
await context.sync();
const summaryBookmark: Word.Bookmark = bookmarks.items.find((bookmark) => bookmark.name === "RangeSampleSummary");
if (!summaryBookmark) {
console.warn("RangeSampleSummary was not found. Choose Insert bookmark first.");
return;
}
const newEnd = paragraphRange.end - 1;
if (newEnd <= summaryBookmark.start) {
console.warn("The bookmark is too short. Run Set up and Insert bookmark again.");
return;
}
summaryBookmark.end = newEnd;
await context.sync();
console.log("Moved the bookmark end before the final period. Get bookmark details to verify the enclosed text.");
});
isColumn
ブックマークがテーブル列の場合に true を返します。
readonly isColumn: boolean;
プロパティ値
boolean
注釈
isEmpty
name
range
Bookmark オブジェクトに含まれるドキュメントの一部を表すRange オブジェクトを返します。
readonly range: Word.Range;
プロパティ値
注釈
start
ブックマークの開始文字位置を指定します。
start: number;
プロパティ値
number
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/manage-range-bookmarks.yaml
// Move the bookmark's start past the word "Project" without changing the document text.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange(Word.RangeLocation.content);
const bookmarks: Word.BookmarkCollection = paragraphRange.bookmarks;
bookmarks.load("items/name,items/end");
paragraphRange.load("start");
await context.sync();
const summaryBookmark: Word.Bookmark = bookmarks.items.find((bookmark) => bookmark.name === "RangeSampleSummary");
if (!summaryBookmark) {
console.warn("RangeSampleSummary was not found. Choose Insert bookmark first.");
return;
}
const newStart = paragraphRange.start + "Project ".length;
if (newStart >= summaryBookmark.end) {
console.warn("The bookmark is too short. Run Set up and Insert bookmark again.");
return;
}
summaryBookmark.start = newStart;
await context.sync();
console.log("Moved the bookmark start past 'Project '. Get bookmark details to verify the enclosed text.");
});
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"
注釈
メソッドの詳細
copyTo(name)
このブックマークを、 name 引数で指定された新しいブックマークにコピーし、 Bookmark オブジェクトを返します。
copyTo(name: string): Word.Bookmark;
パラメーター
- name
-
string
新しいブックマークの名前を指定します。
返品
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/manage-range-bookmarks.yaml
// Create another named bookmark over the same text as the summary bookmark.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange(Word.RangeLocation.content);
const bookmarks: Word.BookmarkCollection = paragraphRange.bookmarks;
bookmarks.load("items/name");
await context.sync();
const summaryBookmark: Word.Bookmark = bookmarks.items.find((bookmark) => bookmark.name === "RangeSampleSummary");
if (!summaryBookmark) {
console.warn("RangeSampleSummary was not found. Choose Insert bookmark first.");
return;
}
if (bookmarks.items.some((bookmark) => bookmark.name === "RangeSampleCopy")) {
console.warn("RangeSampleCopy already exists. Delete the copied bookmark before copying again.");
return;
}
summaryBookmark.copyTo("RangeSampleCopy");
await context.sync();
console.log("Created RangeSampleCopy over the same text. Get bookmark details to inspect both names.");
});
delete()
ブックマークを削除します。
delete(): void;
返品
void
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/manage-range-bookmarks.yaml
// Delete the copied bookmark without deleting its text or the original bookmark.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange(Word.RangeLocation.content);
const bookmarks: Word.BookmarkCollection = paragraphRange.bookmarks;
bookmarks.load("items/name");
await context.sync();
const copiedBookmark: Word.Bookmark = bookmarks.items.find((bookmark) => bookmark.name === "RangeSampleCopy");
if (!copiedBookmark) {
console.warn("RangeSampleCopy was not found. Choose Copy bookmark first.");
return;
}
copiedBookmark.delete();
await context.sync();
console.log("Deleted RangeSampleCopy. Its text and RangeSampleSummary remain. Check copied bookmark to verify.");
});
load(options)
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。
load(options?: Word.Interfaces.BookmarkLoadOptions): Word.Bookmark;
パラメーター
読み込むオブジェクトのプロパティのオプションを指定します。
返品
load(propertyNames)
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。
load(propertyNames?: string | string[]): Word.Bookmark;
パラメーター
- propertyNames
-
string | string[]
読み込むプロパティを指定するコンマ区切りの文字列または文字列の配列。
返品
load(propertyNamesAndPaths)
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。
load(propertyNamesAndPaths?: {
select?: string;
expand?: string;
}): Word.Bookmark;
パラメーター
- propertyNamesAndPaths
-
{ select?: string; expand?: string; }
propertyNamesAndPaths.select は読み込むプロパティを指定するコンマ区切りの文字列であり、 propertyNamesAndPaths.expand は読み込むナビゲーションのプロパティを指定するコンマ区切りの文字列です。
返品
select()
ブックマークを選択します。
select(): void;
返品
void
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/manage-range-bookmarks.yaml
// Select the summary bookmark's current text in the document.
await Word.run(async (context) => {
const paragraphRange: Word.Range = context.document.body.paragraphs.getFirst().getRange(Word.RangeLocation.content);
const bookmarks: Word.BookmarkCollection = paragraphRange.bookmarks;
bookmarks.load("items/name");
await context.sync();
const summaryBookmark: Word.Bookmark = bookmarks.items.find((bookmark) => bookmark.name === "RangeSampleSummary");
if (!summaryBookmark) {
console.warn("RangeSampleSummary was not found. Choose Insert bookmark first.");
return;
}
summaryBookmark.select();
await context.sync();
console.log("Selected RangeSampleSummary in the document.");
});
set(properties, options)
オブジェクトの複数のプロパティを同時に設定します。 適切なプロパティを持つプレーン オブジェクト、または同じ型の別の API オブジェクトを渡すことができます。
set(properties: Interfaces.BookmarkUpdateData, options?: OfficeExtension.UpdateOptions): void;
パラメーター
- properties
- Word.Interfaces.BookmarkUpdateData
メソッドが呼び出されたオブジェクトのプロパティと同型構造のプロパティを持つ JavaScript オブジェクト。
- options
- OfficeExtension.UpdateOptions
プロパティ オブジェクトが読み取り専用プロパティを設定しようとした場合にエラーを抑制するオプションを提供します。
返品
void
set(properties)
既存の読み込まれたオブジェクトに基づいて、オブジェクトに複数のプロパティを同時に設定します。
set(properties: Word.Bookmark): void;
パラメーター
- properties
- Word.Bookmark
返品
void
toJSON()
API オブジェクトが JSON.stringify() に渡されるときに、より有用な出力を提供するために、JavaScript toJSON() メソッドをオーバーライドします。 (次に、JSON.stringify渡されたオブジェクトの toJSON メソッドを呼び出します)。元の Word.Bookmark オブジェクトが API オブジェクトであるのに対し、 toJSON メソッドは、元のオブジェクトから読み込まれた子プロパティの浅いコピーを含むプレーンな JavaScript オブジェクト ( Word.Interfaces.BookmarkData と型指定) を返します。
toJSON(): Word.Interfaces.BookmarkData;
返品
track()
ドキュメントの環境変更に基づいて自動的に調整する目的でオブジェクトを追跡します。 この呼び出しは、 context.trackedObjects.add(thisObject) の短縮形です。 このオブジェクトを .sync 呼び出しと ".run" バッチの連続実行の外部で使用していて、プロパティを設定したり、オブジェクトでメソッドを呼び出したりするときに "InvalidObjectPath" エラーが発生する場合は、オブジェクトが最初に作成されたときに、追跡対象のオブジェクト コレクションにオブジェクトを追加する必要があります。 このオブジェクトがコレクションの一部である場合は、親コレクションも追跡する必要があります。
track(): Word.Bookmark;
返品
untrack()
前に追跡されていた場合、このオブジェクトに関連付けられているメモリを解放します。 この呼び出しは、 context.trackedObjects.remove(thisObject) の省略形です。 追跡対象オブジェクトが多いとホスト アプリケーションの動作が遅くなります。追加したオブジェクトが不要になったら、必ずそれを解放してください。 メモリ リリースを有効にする前に、 context.sync() を呼び出す必要があります。
untrack(): Word.Bookmark;