有人可以提供一个在 Office.js 中获取 DocumentProperties 的简单示例吗? [英] Could someone provide a simple example of getting DocumentProperties in Office.js?

查看:41
本文介绍了有人可以提供一个在 Office.js 中获取 DocumentProperties 的简单示例吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How do I get the author or title of a Word document using Office.js (1.3)?

我阅读了有关 documentProperties 的文档,但我需要一个示例获得正确的语法.

I read the documentation on documentProperties but I need an example to get the syntax right.

感谢帮助!

推荐答案

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

The following code snippet gets the author and title of the document and writes those property values to the console.

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 + "'");
    });
});

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

Note that with the Office.js APIs, you must call the load() method on an object to explicitly load the property value before you'll be able to read it. (You can find information about the load() method in the same article you linked to in your question.)

这篇关于有人可以提供一个在 Office.js 中获取 DocumentProperties 的简单示例吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆