How can I read Excel custom properties in Office Javascript API?

心不动则不痛 提交于 2019-12-09 05:35:24

I know that the question is quite old, but since I stumbled upon it while searching for the answer myself, I'm going to answer it nevertheless. The following JavaScript function is going to print all custom document properties at the end of the current document. It requires version 1.3 of the Office API (see also https://dev.office.com/reference/add-ins/word/documentproperties).

function getProperties() { 
    Word.run(function (context) {
        var body=context.document.body;
        var customDocProps = context.document.properties.customProperties;       
        context.load(customDocProps);
        return context.sync().then(function () {
            for (var i = 0; i < customDocProps.items.length; i++) {
                body.insertText(customDocProps.items[i].key,  Word.InsertLocation.end);
                body.insertText('\n',  Word.InsertLocation.end);
                body.insertText(customDocProps.items[i].value,  Word.InsertLocation.end);
                body.insertText('\n',  Word.InsertLocation.end);
            }
        })
 })
 }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!