Office.CustomXmlParts interface

表示 CustomXmlPart 对象的集合。

注解

应用程序:Word

方法

addAsync(xml, options, callback)

将新的自定义 XML 部件异步添加到文件中。

addAsync(xml, callback)

将新的自定义 XML 部件异步添加到文件中。

getByIdAsync(id, options, callback)

按 ID 异步获取指定的自定义 XML 部件。

getByIdAsync(id, callback)

按 ID 异步获取指定的自定义 XML 部件。

getByNamespaceAsync(ns, options, callback)

按命名空间异步获取指定的自定义 XML 部件。

getByNamespaceAsync(ns, callback)

按命名空间异步获取指定的自定义 XML 部件。

方法详细信息

addAsync(xml, options, callback)

将新的自定义 XML 部件异步添加到文件中。

addAsync(xml: string, options?: Office.AsyncContextOptions, callback?: (result: AsyncResult<CustomXmlPart>) => void): void;

参数

xml

string

要添加到新创建的自定义 XML 部件的 XML。

options
Office.AsyncContextOptions

提供一个选项,用于保留任何类型的上下文数据(保持不变),以便在回调中使用。

callback

(result: Office.AsyncResult<Office.CustomXmlPart>) => void

可选。 回调返回时调用的函数,其唯一参数的类型为 Office.AsyncResultvalue结果的 属性是新创建的 CustomXmlPart 对象。

返回

void

注解

要求集CustomXmlParts

addAsync(xml, callback)

将新的自定义 XML 部件异步添加到文件中。

addAsync(xml: string, callback?: (result: AsyncResult<CustomXmlPart>) => void): void;

参数

xml

string

要添加到新创建的自定义 XML 部件的 XML。

callback

(result: Office.AsyncResult<Office.CustomXmlPart>) => void

可选。 回调返回时调用的函数,其唯一参数的类型为 Office.AsyncResultvalue结果的 属性是新创建的 CustomXmlPart 对象。

返回

void

注解

要求集CustomXmlParts

示例

function addXMLPart() {
    Office.context.document.customXmlParts.addAsync(
        '<root categoryId="1" xmlns="http://tempuri.org"><item name="Cheap Item" price="$193.95"/><item name="Expensive Item" price="$931.88"/></root>',
        function (result) {});
}

function addXMLPartandHandler() {
    Office.context.document.customXmlParts.addAsync(
        "<testns:book xmlns:testns='http://testns.com'><testns:page number='1'>Hello</testns:page><testns:page number='2'>world!</testns:page></testns:book>",
        function(r) { r.value.addHandlerAsync(Office.EventType.DataNodeDeleted,
            function(a) {write(a.type)
            },
                function(s) {write(s.status)
                });
        });
}

// Function that writes to a div with id='message' on the page.
function write(message){
    document.getElementById('message').innerText += message;
}

getByIdAsync(id, options, callback)

按 ID 异步获取指定的自定义 XML 部件。

getByIdAsync(id: string, options?: Office.AsyncContextOptions, callback?: (result: AsyncResult<CustomXmlPart>) => void): void;

参数

id

string

自定义 XML 部件的 GUID(包括前后括号)。

options
Office.AsyncContextOptions

提供一个选项,用于保留任何类型的上下文数据(保持不变),以便在回调中使用。

callback

(result: Office.AsyncResult<Office.CustomXmlPart>) => void

可选。 回调返回时调用的函数,其唯一参数的类型为 Office.AsyncResultvalue结果的 属性是一个 CustomXmlPart 对象,该对象表示指定的自定义 XML 部件。 如果没有具有指定 ID 的自定义 XML 部件,该方法将返回 null。

返回

void

注解

要求集CustomXmlParts

示例

function showXMLPartInnerXML() {
    Office.context.document.customXmlParts.getByIdAsync(
        "{3BC85265-09D6-4205-B665-8EB239A8B9A1}", function (result) {
        const xmlPart = result.value;
        xmlPart.getXmlAsync({}, function (eventArgs) {
            write(eventArgs.value);
        });
    });
}
// Function that writes to a div with id='message' on the page.
function write(message){
    document.getElementById('message').innerText += message; 
}

getByIdAsync(id, callback)

按 ID 异步获取指定的自定义 XML 部件。

getByIdAsync(id: string, callback?: (result: AsyncResult<CustomXmlPart>) => void): void;

参数

id

string

自定义 XML 部件的 GUID(包括前后括号)。

callback

(result: Office.AsyncResult<Office.CustomXmlPart>) => void

可选。 回调返回时调用的函数,其唯一参数的类型为 Office.AsyncResultvalue结果的 属性是一个 CustomXmlPart 对象,该对象表示指定的自定义 XML 部件。 如果没有具有指定 ID 的自定义 XML 部件,该方法将返回 null。

返回

void

注解

要求集CustomXmlParts

getByNamespaceAsync(ns, options, callback)

按命名空间异步获取指定的自定义 XML 部件。

getByNamespaceAsync(ns: string, options?: Office.AsyncContextOptions, callback?: (result: AsyncResult<CustomXmlPart[]>) => void): void;

参数

ns

string

命名空间 URI。

options
Office.AsyncContextOptions

提供一个选项,用于保留任何类型的上下文数据(保持不变),以便在回调中使用。

callback

(result: Office.AsyncResult<Office.CustomXmlPart[]>) => void

可选。 回调返回时调用的函数,其唯一参数的类型为 Office.AsyncResult。 结果 value 的 属性是与指定命名空间匹配的 CustomXmlPart 对象的数组。

返回

void

注解

要求集CustomXmlParts

getByNamespaceAsync(ns, callback)

按命名空间异步获取指定的自定义 XML 部件。

getByNamespaceAsync(ns: string, callback?: (result: AsyncResult<CustomXmlPart[]>) => void): void;

参数

ns

string

命名空间 URI。

callback

(result: Office.AsyncResult<Office.CustomXmlPart[]>) => void

可选。 回调返回时调用的函数,其唯一参数的类型为 Office.AsyncResult。 结果 value 的 属性是与指定命名空间匹配的 CustomXmlPart 对象的数组。

返回

void

注解

要求集CustomXmlParts

示例

function showXMLPartsInNamespace() {
    Office.context.document.customXmlParts.getByNamespaceAsync(
        "http://tempuri.org", 
        function (eventArgs) {
            write("Found " + eventArgs.value.length + " parts with this namespace");
    }); 
}
// Function that writes to a div with id='message' on the page.
function write(message){
    document.getElementById('message').innerText += message; 
}