Office js OfficeJs标题内容控件

Office js OfficeJs标题内容控件,office-js,Office Js,我正在尝试获取标题的内容控件,但无法获取它们。 我最终使用ooxml,但有点痛苦 function getContenControlHeader(tag) { // Run a batch operation against the Word object model. Word.run(function (context) { // Create a proxy sectionsCollection object. var mySection

我正在尝试获取标题的内容控件,但无法获取它们。 我最终使用ooxml,但有点痛苦

function getContenControlHeader(tag) {

    // Run a batch operation against the Word object model.
    Word.run(function (context) {

        // Create a proxy sectionsCollection object.
        var mySections = context.document.sections;

        // Queue a commmand to load the sections.
        context.load(mySections, 'body/style');

        return context.sync().then(function () {

            var myHeader = mySections.items[0].getHeader('primary');
            return context.sync().then(function () {

                var contentControl = myHeader.contentControls.getByTag(tag);

                // Queue a command to load the text property for a content control.
                context.load(contentControl, 'text');

                // Synchronize the document state by executing the queued commands, and return a promise to indicate task completion.
                return context.sync().then(function () {
                        console.log(contentControl.items[0].text);
                });
            });
        });
    });
}

此代码段无效,返回的列表为空。文档正文上的内容控件的这段代码非常有用。

我在Word及其工作区的最新公开版本(16.7766)中尝试了您的代码,只要我提供了有效的标记。也许不用说,但是: A.请检查标题中是否确实存在带有您提供给getByTag的标记的内容控件

如果仍不起作用,请提供更多信息: A.你是在Windows、在线、Mac上测试这个吗? B建造编号

我还建议您捕获一个异常,以了解有关可能发生的情况的更多详细信息。请检查我添加到示例中的处理程序:

函数getContenControlHeader(标记){
//对Word对象模型运行批处理操作。
运行(函数(上下文){
//创建代理sectionsCollection对象。
var mySections=context.document.sections;
//将命令排队以加载节。
加载(mySections,“body/style”);
返回context.sync().then(函数(){
var myHeader=mySections.items[0]。getHeader('primary');
返回context.sync().then(函数(){
var contentControl=myHeader.contentControls.getByTag(“示例”);
//将命令排入队列以加载内容控件的文本属性。
load(contentControl,“text”);
//通过执行排队命令同步文档状态,并返回指示任务完成的承诺。
返回context.sync().then(函数(){
console.log(contentControl.items[0].text);
});
});
});
})
.catch(函数(e){
控制台日志(e.message);
}   ) 

}
对不起,我忘了回答。试过这个但没用,我现在就试试。谢谢。你好,我不清楚你是否真的试过我的样品。你有没有>如果没有,你会得到什么错误,并提供更多关于你的office客户端构建等的详细信息。谢谢