Word.Page class
ドキュメント内のページを表します。
Page オブジェクトはページ レイアウトとコンテンツを管理します。
- Extends
注釈
[ API set: WordApiDesktop 1.2 ]
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/get-pages.yaml
await Word.run(async (context) => {
// Gets pages of the selection.
const pages: Word.PageCollection = context.document.getSelection().pages;
pages.load();
await context.sync();
// Log info for pages included in selection.
console.log(pages);
const pagesIndexes = [];
const pagesText = [];
for (let i = 0; i < pages.items.length; i++) {
const page = pages.items[i];
page.load("index");
pagesIndexes.push(page);
const range = page.getRange();
range.load("text");
pagesText.push(range);
}
await context.sync();
for (let i = 0; i < pagesIndexes.length; i++) {
console.log(`Index info for page ${i + 1} in the selection: ${pagesIndexes[i].index}`);
console.log("Text of that page in the selection:", pagesText[i].text);
}
});
プロパティ
| breaks | ページの区切りを表す |
| context | オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。 |
| height | [ページ設定] ダイアログ ボックスで定義されている用紙の高さをポイント単位で取得します。 |
| index | ページのインデックスを取得します。 ページ インデックスは 1 から始まるものであり、ユーザーのカスタム ページ番号とは無関係です。 |
| width | [ページ設定] ダイアログ ボックスで定義されている用紙の幅をポイント単位で取得します。 |
メソッド
| get |
ウィンドウ内の次のページを取得します。 このページが最後のページの場合は、 |
| get |
次のページを取得します。 このページが最後のページの場合、このメソッドは |
| get |
ページ全体、またはページの始点または終了位置を範囲として取得します。 |
| load(options) | オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、 |
| load(property |
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、 |
| load(property |
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、 |
| toJSON() | API オブジェクトが |
| track() | ドキュメントの環境変更に基づいて自動的に調整する目的でオブジェクトを追跡します。 この呼び出しは、 context.trackedObjects.add(thisObject)の短縮形です。 このオブジェクトを |
| untrack() | 前に追跡されていた場合、このオブジェクトに関連付けられているメモリを解放します。 この呼び出しは 、context.trackedObjects.remove(thisObject)の短縮形です。 追跡対象オブジェクトが多いとホスト アプリケーションの動作が遅くなります。追加したオブジェクトが不要になったら、必ずそれを解放してください。 メモリ解放が有効になる前に、 |
プロパティの詳細
breaks
ページの区切りを表す BreakCollection オブジェクトを取得します。
readonly breaks: Word.BreakCollection;
プロパティ値
注釈
context
オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。
context: RequestContext;
プロパティ値
height
[ページ設定] ダイアログ ボックスで定義されている用紙の高さをポイント単位で取得します。
readonly height: number;
プロパティ値
number
注釈
index
ページのインデックスを取得します。 ページ インデックスは 1 から始まるものであり、ユーザーのカスタム ページ番号とは無関係です。
readonly index: number;
プロパティ値
number
注釈
[ API set: WordApiDesktop 1.2 ]
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/get-pages.yaml
await Word.run(async (context) => {
// Gets the pages that contain the third paragraph.
const paragraphs: Word.ParagraphCollection = context.document.body.paragraphs;
paragraphs.load();
await context.sync();
const paraThree = paragraphs.items[2];
const rangeOfParagraph = paraThree.getRange();
const pages: Word.PageCollection = rangeOfParagraph.pages;
pages.load();
await context.sync();
// Log info for pages in range.
console.log(pages);
const pagesIndexes = [];
const pagesText = [];
for (let i = 0; i < pages.items.length; i++) {
const page = pages.items[i];
page.load("index");
pagesIndexes.push(page);
const range = page.getRange();
range.load("text");
pagesText.push(range);
}
await context.sync();
for (let i = 0; i < pagesIndexes.length; i++) {
console.log(`Index of page ${i + 1} that contains the third paragraph: ${pagesIndexes[i].index}`);
console.log("Text of that page:", pagesText[i].text);
}
});
width
[ページ設定] ダイアログ ボックスで定義されている用紙の幅をポイント単位で取得します。
readonly width: number;
プロパティ値
number
注釈
メソッドの詳細
getNext()
ウィンドウ内の次のページを取得します。 このページが最後のページの場合は、 ItemNotFound エラーをスローします。
getNext(): Word.Page;
戻り値
注釈
getNextOrNullObject()
次のページを取得します。 このページが最後のページの場合、このメソッドは isNullObject プロパティを true に設定したオブジェクトを返します。 詳細については、「 *OrNullObject メソッドとプロパティ」を参照してください。
getNextOrNullObject(): Word.Page;
戻り値
注釈
getRange(rangeLocation)
ページ全体、またはページの始点または終了位置を範囲として取得します。
getRange(rangeLocation?: Word.RangeLocation.whole | Word.RangeLocation.start | Word.RangeLocation.end | "Whole" | "Start" | "End"): Word.Range;
パラメーター
省略可能。 範囲の場所は、 whole、 start、または endである必要があります。
戻り値
注釈
[ API set: WordApiDesktop 1.2 ]
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/get-pages.yaml
await Word.run(async (context) => {
// Gets pages of the selection.
const pages: Word.PageCollection = context.document.getSelection().pages;
pages.load();
await context.sync();
// Log info for pages included in selection.
console.log(pages);
const pagesIndexes = [];
const pagesText = [];
for (let i = 0; i < pages.items.length; i++) {
const page = pages.items[i];
page.load("index");
pagesIndexes.push(page);
const range = page.getRange();
range.load("text");
pagesText.push(range);
}
await context.sync();
for (let i = 0; i < pagesIndexes.length; i++) {
console.log(`Index info for page ${i + 1} in the selection: ${pagesIndexes[i].index}`);
console.log("Text of that page in the selection:", pagesText[i].text);
}
});
load(options)
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。
load(options?: Word.Interfaces.PageLoadOptions): Word.Page;
パラメーター
- options
- Word.Interfaces.PageLoadOptions
読み込むオブジェクトのプロパティのオプションを提供します。
戻り値
load(propertyNames)
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。
load(propertyNames?: string | string[]): Word.Page;
パラメーター
- propertyNames
-
string | string[]
読み込むプロパティを指定するコンマ区切り文字列または文字列の配列。
戻り値
load(propertyNamesAndPaths)
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。
load(propertyNamesAndPaths?: {
select?: string;
expand?: string;
}): Word.Page;
パラメーター
- propertyNamesAndPaths
-
{ select?: string; expand?: string; }
propertyNamesAndPaths.select は読み込むプロパティを指定するコンマ区切りの文字列で、 propertyNamesAndPaths.expand は読み込むナビゲーション プロパティを指定するコンマ区切りの文字列です。
戻り値
toJSON()
API オブジェクトがJSON.stringify()に渡されたときにより便利な出力を提供するために、JavaScript toJSON() メソッドをオーバーライドします。 (JSON.stringify、それに渡されるオブジェクトの toJSON メソッドを呼び出します)。元の Word.Page オブジェクトは API オブジェクトですが、 toJSON メソッドは、元のオブジェクトから読み込まれた子プロパティの浅いコピーを含むプレーンな JavaScript オブジェクト ( Word.Interfaces.PageData として型指定) を返します。
toJSON(): Word.Interfaces.PageData;
戻り値
track()
ドキュメントの環境変更に基づいて自動的に調整する目的でオブジェクトを追跡します。 この呼び出しは、 context.trackedObjects.add(thisObject)の短縮形です。 このオブジェクトを .sync 呼び出しで使用し、".run" バッチのシーケンシャル実行の外部でプロパティを設定するとき、またはオブジェクトに対してメソッドを呼び出すときに "InvalidObjectPath" エラーが発生する場合は、オブジェクトが最初に作成されたときに、追跡対象のオブジェクト コレクションにオブジェクトを追加する必要があります。 このオブジェクトがコレクションの一部である場合は、親コレクションも追跡する必要があります。
track(): Word.Page;
戻り値
untrack()
前に追跡されていた場合、このオブジェクトに関連付けられているメモリを解放します。 この呼び出しは 、context.trackedObjects.remove(thisObject)の短縮形です。 追跡対象オブジェクトが多いとホスト アプリケーションの動作が遅くなります。追加したオブジェクトが不要になったら、必ずそれを解放してください。 メモリ解放が有効になる前に、 context.sync() を呼び出す必要があります。
untrack(): Word.Page;