Excel.CustomXmlPartScopedCollection class

カスタム XML パーツのスコープ付きコレクション。 スコープ付きコレクションは、何らかの操作 (名前空間によるフィルター処理など) の結果です。 スコープ付きコレクションは、これ以上スコープを設定できません。

Extends

注釈

[ API セット: ExcelApi 1.5 ]

プロパティ

context

オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。

items

このコレクション内に読み込まれた子アイテムを取得します。

メソッド

getCount()

コレクションに含まれる CustomXML パーツの数を取得します。

getItem(id)

ID に基づいて、カスタム XML パーツを取得します。

getItemOrNullObject(id)

ID に基づいて、カスタム XML パーツを取得します。 CustomXmlPartが存在しない場合、このメソッドは プロパティが に設定されたオブジェクトをisNullObjecttrue返します。 詳細については、「 *OrNullObject メソッドとプロパティ」を参照してください。

getOnlyItem()

コレクションに含まれる項目が 1 つだけの場合、このメソッドはその項目を返します。 それ以外の場合、このメソッドはエラーを生成します。

getOnlyItemOrNullObject()

コレクションに含まれる項目が 1 つだけの場合、このメソッドはその項目を返します。 それ以外の場合、このメソッドは を返します null

load(options)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

load(propertyNames)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

load(propertyNamesAndPaths)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

toJSON()

API オブジェクトが に渡されたときにより便利な出力を提供するために、JavaScript toJSON() メソッドを JSON.stringify()オーバーライドします。 (JSON.stringifyさらに、渡される オブジェクトの メソッドを呼び出 toJSON します)。元 Excel.CustomXmlPartScopedCollection のオブジェクトは API オブジェクトですが、 toJSON メソッドは、コレクションの項目から読み込まれたプロパティの浅いコピーを含む "items" 配列を含むプレーンな JavaScript オブジェクト (として Excel.Interfaces.CustomXmlPartScopedCollectionData型指定) を返します。

プロパティの詳細

context

オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。

context: RequestContext;

プロパティ値

items

このコレクション内に読み込まれた子アイテムを取得します。

readonly items: Excel.CustomXmlPart[];

プロパティ値

メソッドの詳細

getCount()

コレクションに含まれる CustomXML パーツの数を取得します。

getCount(): OfficeExtension.ClientResult<number>;

戻り値

注釈

[ API セット: ExcelApi 1.5 ]

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/18-custom-xml-parts/test-xml-for-unique-namespace.yaml

await Excel.run(async (context) => {
    $("#display-xml").text("");
    const contosoNamespace = "http://schemas.contoso.com/review/1.0";
    const customXmlParts = context.workbook.customXmlParts;
    const filteredXmlParts = customXmlParts.getByNamespace(contosoNamespace);
    const numberOfPartsInNamespace = filteredXmlParts.getCount();

    await context.sync();

    if (numberOfPartsInNamespace.value == 1) {
        const onlyXmlPartInNamespace = filteredXmlParts.getOnlyItem();
        const xmlBlob = onlyXmlPartInNamespace.getXml();

        await context.sync();

        // Make it a bit more readable.
        const readableXml = xmlBlob.value.replace(/></g, ">\n<");

        $("#display-xml").text(`The only XML part in the namespace ${contosoNamespace} is:
            ${readableXml}`);

    } else {
        console.log(`There are ${numberOfPartsInNamespace.value} XML parts with namespace ${contosoNamespace}. There should be exactly 1.`);
    }        

    await context.sync();
});

getItem(id)

ID に基づいて、カスタム XML パーツを取得します。

getItem(id: string): Excel.CustomXmlPart;

パラメーター

id

string

取得するオブジェクトの ID。

戻り値

注釈

[ API セット: ExcelApi 1.5 ]

getItemOrNullObject(id)

ID に基づいて、カスタム XML パーツを取得します。 CustomXmlPartが存在しない場合、このメソッドは プロパティが に設定されたオブジェクトをisNullObjecttrue返します。 詳細については、「 *OrNullObject メソッドとプロパティ」を参照してください。

getItemOrNullObject(id: string): Excel.CustomXmlPart;

パラメーター

id

string

取得するオブジェクトの ID。

戻り値

注釈

[ API セット: ExcelApi 1.5 ]

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/18-custom-xml-parts/create-set-get-and-delete-custom-xml-parts.yaml

await Excel.run(async (context) => {
    const settings = context.workbook.settings;
    const xmlPartIDSetting = settings.getItemOrNullObject("ContosoReviewXmlPartId").load("value");
    await context.sync();

    if (xmlPartIDSetting.value) {   
        let customXmlPart = context.workbook.customXmlParts.getItem(xmlPartIDSetting.value);
        const xmlBlob = customXmlPart.getXml();
        customXmlPart.delete();
        customXmlPart = context.workbook.customXmlParts.getItemOrNullObject(xmlPartIDSetting.value);

        await context.sync();

        if (customXmlPart.isNullObject) {
            $("#display-xml").text(`The XML part with the id ${xmlPartIDSetting.value} has been deleted.`);

            // Delete the unneeded setting too.
            xmlPartIDSetting.delete();            
        } else {
            const readableXml = addLineBreaksToXML(xmlBlob.value);
            const strangeMessage = `This is strange. The XML part with the id ${xmlPartIDSetting.value} has not been deleted:\n${readableXml}`
            $("#display-xml").text(strangeMessage);
        }

        await context.sync();
    }
});

getOnlyItem()

コレクションに含まれる項目が 1 つだけの場合、このメソッドはその項目を返します。 それ以外の場合、このメソッドはエラーを生成します。

getOnlyItem(): Excel.CustomXmlPart;

戻り値

注釈

[ API セット: ExcelApi 1.5 ]

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/18-custom-xml-parts/test-xml-for-unique-namespace.yaml

await Excel.run(async (context) => {
    $("#display-xml").text("");
    const contosoNamespace = "http://schemas.contoso.com/review/1.0";
    const customXmlParts = context.workbook.customXmlParts;
    const filteredXmlParts = customXmlParts.getByNamespace(contosoNamespace);
    const numberOfPartsInNamespace = filteredXmlParts.getCount();

    await context.sync();

    if (numberOfPartsInNamespace.value == 1) {
        const onlyXmlPartInNamespace = filteredXmlParts.getOnlyItem();
        const xmlBlob = onlyXmlPartInNamespace.getXml();

        await context.sync();

        // Make it a bit more readable.
        const readableXml = xmlBlob.value.replace(/></g, ">\n<");

        $("#display-xml").text(`The only XML part in the namespace ${contosoNamespace} is:
            ${readableXml}`);

    } else {
        console.log(`There are ${numberOfPartsInNamespace.value} XML parts with namespace ${contosoNamespace}. There should be exactly 1.`);
    }        

    await context.sync();
});

getOnlyItemOrNullObject()

コレクションに含まれる項目が 1 つだけの場合、このメソッドはその項目を返します。 それ以外の場合、このメソッドは を返します null

getOnlyItemOrNullObject(): Excel.CustomXmlPart;

戻り値

注釈

[ API セット: ExcelApi 1.5 ]

load(options)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

load(options?: Excel.Interfaces.CustomXmlPartScopedCollectionLoadOptions & Excel.Interfaces.CollectionLoadOptions): Excel.CustomXmlPartScopedCollection;

パラメーター

options

Excel.Interfaces.CustomXmlPartScopedCollectionLoadOptions & Excel.Interfaces.CollectionLoadOptions

読み込むオブジェクトのプロパティのオプションを提供します。

戻り値

load(propertyNames)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

load(propertyNames?: string | string[]): Excel.CustomXmlPartScopedCollection;

パラメーター

propertyNames

string | string[]

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

戻り値

load(propertyNamesAndPaths)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

load(propertyNamesAndPaths?: OfficeExtension.LoadOption): Excel.CustomXmlPartScopedCollection;

パラメーター

propertyNamesAndPaths
OfficeExtension.LoadOption

propertyNamesAndPaths.select は、読み込むプロパティを指定するコンマ区切り文字列で propertyNamesAndPaths.expand 、読み込むナビゲーション プロパティを指定するコンマ区切りの文字列です。

戻り値

toJSON()

API オブジェクトが に渡されたときにより便利な出力を提供するために、JavaScript toJSON() メソッドを JSON.stringify()オーバーライドします。 (JSON.stringifyさらに、渡される オブジェクトの メソッドを呼び出 toJSON します)。元 Excel.CustomXmlPartScopedCollection のオブジェクトは API オブジェクトですが、 toJSON メソッドは、コレクションの項目から読み込まれたプロパティの浅いコピーを含む "items" 配列を含むプレーンな JavaScript オブジェクト (として Excel.Interfaces.CustomXmlPartScopedCollectionData型指定) を返します。

toJSON(): Excel.Interfaces.CustomXmlPartScopedCollectionData;

戻り値