Excel.CustomXmlPart class

ブック内のカスタム XML パーツ オブジェクトを表します。

Extends

注釈

[ API セット: ExcelApi 1.5 ]

プロパティ

context

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

id

カスタム XML パーツの ID。

namespaceUri

カスタム XML パーツの名前空間 URI。

メソッド

delete()

カスタム XML パーツを削除します。

getXml()

カスタム XML パーツのすべての XML コンテンツを取得します。

load(options)

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

load(propertyNames)

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

load(propertyNamesAndPaths)

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

setXml(xml)

カスタム XML パーツのすべての XML コンテンツを設定します。

toJSON()

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

プロパティの詳細

context

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

context: RequestContext;

プロパティ値

id

カスタム XML パーツの ID。

readonly id: string;

プロパティ値

string

注釈

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

namespaceUri

カスタム XML パーツの名前空間 URI。

readonly namespaceUri: string;

プロパティ値

string

注釈

[ API セット: ExcelApi 1.5 ]

メソッドの詳細

delete()

カスタム XML パーツを削除します。

delete(): void;

戻り値

void

注釈

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

getXml()

カスタム XML パーツのすべての XML コンテンツを取得します。

getXml(): OfficeExtension.ClientResult<string>;

戻り値

注釈

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

load(options)

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

load(options?: Excel.Interfaces.CustomXmlPartLoadOptions): Excel.CustomXmlPart;

パラメーター

options
Excel.Interfaces.CustomXmlPartLoadOptions

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

戻り値

load(propertyNames)

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

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

パラメーター

propertyNames

string | string[]

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

戻り値

load(propertyNamesAndPaths)

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

load(propertyNamesAndPaths?: {
            select?: string;
            expand?: string;
        }): Excel.CustomXmlPart;

パラメーター

propertyNamesAndPaths

{ select?: string; expand?: string; }

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

戻り値

setXml(xml)

カスタム XML パーツのすべての XML コンテンツを設定します。

setXml(xml: string): void;

パラメーター

xml

string

パーツの XML コンテンツ。

戻り値

void

注釈

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

toJSON()

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

toJSON(): Excel.Interfaces.CustomXmlPartData;

戻り値