Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could someone provide a simple example of getting DocumentProperties in Office.js?

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

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

Help appreciated!

like image 921
11teenth Avatar asked Sep 26 '17 15:09

11teenth


Video Answer


1 Answers

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

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.)

like image 161
Kim Brandl Avatar answered Sep 24 '22 10:09

Kim Brandl