【问题标题】:How can I read Excel custom properties in Office Javascript API?如何在 Office Javascript API 中读取 Excel 自定义属性?
【发布时间】:2015-05-21 13:00:00
【问题描述】:

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

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

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

【问题讨论】:

    标签: javascript excel custom-properties apps-for-office


    【解决方案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);
                }
            })
     })
     }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-11
      • 2014-08-08
      相关资源
      最近更新 更多