Is it possible to using Custom Properties (JavaScript API 1.3 for Office)

不羁岁月 提交于 2019-12-12 01:14:29

问题


I saw the MS Office js api 1.3 document about custom properties. But I can not read any custom property item from word settings by office js.

       `Word.run(function (context) {

            // Create a proxy object for the document.
            var thisDocument = context.document;

            var customProperties = thisDocument.properties.customProperties;

            context.load(customProperties);

            return context.sync().then(function () {
                var getcount = customProperties.getCount();


                console.log(customProperties.items);
                return context.sync().then(function () {
                    console.log(getcount.value);
                });
            });
        })`

The customProperties.items alway return empty array. I also can not find the set method in customProperties My custom property is show in this (https://i.stack.imgur.com/AywDo.png).

Does MS Office js api not support to access custom properties in word yet?


回答1:


CallOfDuty: I think what's happening is that you don't have an updated version of your Office Client (you need 16/0.7766+). I ran your code in a recent build and I am getting the custom properties using your exact same code. So just please make sure you are working on a fresh update, here are some instructions on how to do it.

Btw, I just got a simplified version of your code. Hope this helps!

function getProperties() { 
    Word.run(function (context) {
        var customDocProps = context.document.properties.customProperties;
        context.load(customDocProps);
        return context.sync()
            .then(function () {
                console.log(customDocProps.items.length);
             })
     })
}


来源:https://stackoverflow.com/questions/42106626/is-it-possible-to-using-custom-properties-javascript-api-1-3-for-office

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!