有人可以提供在Office.js中获取DocumentProperties的简单示例吗?

11t*_*nth 5 ms-word office-js

如何使用Office.js(1.3)获取Word文档的作者或标题?

我阅读了有关documentProperties的文档,但需要一个示例来正确使用语法。

帮助赞赏!

Kim*_*ndl 5

以下代码片段获取文档的作者和标题,并将这些属性值写入控制台。

Word.run(function (context) {
  var document = context.document;
  document.properties.load("author, title");
  
  return context.sync()
    .then(function () {
      console.log("The author of this document is " + document.properties.author + " and the title is '" + document.properties.title + "'");
    });
});
Run Code Online (Sandbox Code Playgroud)

请注意,使用 Office.js API,您必须调用load()对象上的方法以显式加载属性值,然后才能读取它。(您可以在问题中链接的同一篇文章load()中找到有关该方法的信息。)