1

我有一个选项卡窗格应用程序,它需要访问当前 MS Office 文档(可以是 Word 或 Excel)的自定义属性。

Office JavaScript API 似乎没有内置的方法来执行此操作,但在 Word 中,我使用 Office.context.document.getFileAsync() 方法返回整个文件。然后我可以解压缩它,读入 custom.xml 文件,然后浏览 XML 以获取自定义属性。

但是,Office.context.document.getFileAsync() 在 Excel 中不可用。还有另一种读取自定义属性的方法吗?

4

1 回答 1

1

我知道这个问题已经很老了,但是由于我自己在寻找答案时偶然发现了它,所以我还是要回答它。以下 JavaScript 函数将在当前文档的末尾打印所有自定义文档属性。它需要 Office API 1.3 版(另请参阅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);
            }
        })
 })
 }
于 2017-10-06T20:14:25.407 回答