Is it possible to using Custom Properties (JavaScr

2019-09-14 20:44发布

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条回答
我只想做你的唯一
2楼-- · 2019-09-14 21:33

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

查看更多
登录 后发表回答