OfficeExtension.LoadOption interface

読み込むオブジェクトのプロパティを指定します。 この読み込みは、sync() メソッドが実行されたときに発生します。 これにより、Office オブジェクトと対応する JavaScript プロキシ オブジェクトの間で状態が同期されます。

注釈

Word の場合、プロパティとページング情報を指定するための推奨される方法は、文字列リテラルを使用することです。 最初の 2 つの例は、段落コレクションの段落のテキストおよびフォント サイズのプロパティを要求するための推奨される方法を示しています。

context.load(paragraphs, 'text, font/size');

paragraphs.load('text, font/size');

次に、オブジェクト表記 (ページングを含む) を使用する、類似の例を示します。

context.load(paragraphs, {select: 'text, font/size', expand: 'font', top: 50, skip: 0});

paragraphs.load({select: 'text, font/size', expand: 'font', top: 50, skip: 0});

select ステートメントのフォント オブジェクトで特定のプロパティを指定しない場合、すべてのフォント プロパティが読み込まれることを expand ステートメントが単独で示します。

// This example shows how to get the paragraphs in the Word document
// along with their text and font size properties.

// Run a batch operation against the Word object model.
Word.run(function (context) {
    // Create a proxy object for the paragraphs collection.
    const paragraphs = context.document.body.paragraphs;

    // Queue a command to load the text and font properties.
    // It is best practice to always specify the property set.
    // Otherwise, all properties are returned on the object.
    context.load(paragraphs, 'text, font/size');

    // Synchronize the document state by executing the queued commands,
    // and return a promise to indicate task completion.
    return context.sync().then(function () {
        // Insert code that works with the paragraphs loaded by context.load().
    })
})
.catch(function (error) {
    console.log('Error: ' + JSON.stringify(error));
    if (error instanceof OfficeExtension.Error) {
        console.log('Debug info: ' + JSON.stringify(error.debugInfo));
    }
});

プロパティ

expand

読み込むナビゲーション プロパティを指定するコンマ区切り文字列または文字列の配列。

select

読み込むプロパティを指定するコンマ区切り文字列または文字列の配列。

skip

コレクション型でのみ使用できます。 結果に含まれない、スキップするコレクション内の項目の数を指定します。 top を指定すると、指定した数の項目をスキップした後に結果セットが開始されます。

top

コレクション型でのみ使用できます。 結果に含めることができるコレクション項目の最大数を指定します。

プロパティの詳細

expand

読み込むナビゲーション プロパティを指定するコンマ区切り文字列または文字列の配列。

expand?: string | string[];

プロパティ値

string | string[]

select

読み込むプロパティを指定するコンマ区切り文字列または文字列の配列。

select?: string | string[];

プロパティ値

string | string[]

skip

コレクション型でのみ使用できます。 結果に含まれない、スキップするコレクション内の項目の数を指定します。 top を指定すると、指定した数の項目をスキップした後に結果セットが開始されます。

skip?: number;

プロパティ値

number

top

コレクション型でのみ使用できます。 結果に含めることができるコレクション項目の最大数を指定します。

top?: number;

プロパティ値

number

// This OneNote example shows how to get the page title and indentation level
// of the top five pages in the current section.
OneNote.run(function (context) {
    // Get the pages in the current section.
    const pages = context.application.getActiveSection().pages;

    // Queue a command to load the pages.           
    pages.load({ "select":"title,pageLevel", "top":5, "skip":0 });
    return context.sync()
        .then(function() {
            // Iterate through the collection of pages.    
            $.each(pages.items, function(index, page) {
                // Show some properties.
                console.log("Page title: " + page.title);
                console.log("Indentation level: " + page.pageLevel);
            });
        }).catch(function(error) {
            console.log("Error: " + error);
            if (error instanceof OfficeExtension.Error) {
                console.log("Debug info: " + JSON.stringify(error.debugInfo));
            }
        })
    });