Excel.CustomXmlPartCollection class

カスタム XML パーツのコレクション。

Extends

注釈

[ API セット: ExcelApi 1.5 ]

プロパティ

context

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

items

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

メソッド

add(xml)

ブックに新しいカスタム XML パーツを追加します。

getByNamespace(namespaceUri)

名前空間が指定した名前空間に一致する、カスタム XML パーツの新しい範囲のコレクションを取得します。

getCount()

コレクション内のカスタム XML パーツの数を取得します。

getItem(id)

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

getItemOrNullObject(id)

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

load(options)

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

load(propertyNames)

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

load(propertyNamesAndPaths)

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

toJSON()

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

プロパティの詳細

context

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

context: RequestContext;

プロパティ値

items

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

readonly items: Excel.CustomXmlPart[];

プロパティ値

メソッドの詳細

add(xml)

ブックに新しいカスタム XML パーツを追加します。

add(xml: string): Excel.CustomXmlPart;

パラメーター

xml

string

XML コンテンツ。 有効な XML フラグメントである必要があります。

戻り値

注釈

[ 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) => {
    // You must have the xmlns attribute to populate the 
    // CustomXml.namespaceUri property.
    const originalXml = "<Reviewers xmlns='http://schemas.contoso.com/review/1.0'><Reviewer>Juan</Reviewer><Reviewer>Hong</Reviewer><Reviewer>Sally</Reviewer></Reviewers>";
    const customXmlPart = context.workbook.customXmlParts.add(originalXml);
    customXmlPart.load("id");
    const xmlBlob = customXmlPart.getXml();

    await context.sync();

    const readableXml = addLineBreaksToXML(xmlBlob.value);
    $("#display-xml").text(readableXml);

    // Store the XML part's ID in a setting.
    const settings = context.workbook.settings;
    settings.add("ContosoReviewXmlPartId", customXmlPart.id);

    await context.sync();
});

getByNamespace(namespaceUri)

名前空間が指定した名前空間に一致する、カスタム XML パーツの新しい範囲のコレクションを取得します。

getByNamespace(namespaceUri: string): Excel.CustomXmlPartScopedCollection;

パラメーター

namespaceUri

string

これは完全修飾スキーマ URI である必要があります。たとえば、"http://schemas.contoso.com/review/1.0"。

戻り値

注釈

[ 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();
});

getCount()

コレクション内のカスタム XML パーツの数を取得します。

getCount(): OfficeExtension.ClientResult<number>;

戻り値

注釈

[ API セット: ExcelApi 1.5 ]

getItem(id)

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

getItem(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) {   
        const customXmlPart = context.workbook.customXmlParts.getItem(xmlPartIDSetting.value);

        // The setXml method does a whole-for-whole replacement 
        // of the entire XML.
        customXmlPart.setXml("<Reviewers xmlns='http://schemas.contoso.com/review/1.0'><Reviewer>John</Reviewer><Reviewer>Hitomi</Reviewer></Reviewers>");
        const xmlBlob = customXmlPart.getXml();
        await context.sync();

        const readableXml = addLineBreaksToXML(xmlBlob.value);
        $("#display-xml").text(readableXml);
        await context.sync();
    }
});

getItemOrNullObject(id)

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

getItemOrNullObject(id: string): Excel.CustomXmlPart;

パラメーター

id

string

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

戻り値

注釈

[ API セット: ExcelApi 1.5 ]

load(options)

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

load(options?: Excel.Interfaces.CustomXmlPartCollectionLoadOptions & Excel.Interfaces.CollectionLoadOptions): Excel.CustomXmlPartCollection;

パラメーター

options

Excel.Interfaces.CustomXmlPartCollectionLoadOptions & Excel.Interfaces.CollectionLoadOptions

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

戻り値

load(propertyNames)

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

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

パラメーター

propertyNames

string | string[]

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

戻り値

load(propertyNamesAndPaths)

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

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

パラメーター

propertyNamesAndPaths
OfficeExtension.LoadOption

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

戻り値

toJSON()

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

toJSON(): Excel.Interfaces.CustomXmlPartCollectionData;

戻り値