如何通过office JS API获取word中的活动文档信息/文本

问题描述 投票:0回答:1

我想获取当前活动文档信息/文本,用户可以在屏幕上看到。 我们可以通过Word JS API 来实现吗?或者有没有其他方法可以获取 JS Addins 的当前/活动页面。

office365 office-js office-addins add-in word-addins
1个回答
0
投票

我认为无法获取当前/活动页面

selection

参见选择文档

Word.run(function (context) {
  // Get the currently active document.
  var document = context.document;

  // Load the body of the document to access its text.
  var body = document.body;
  body.load("text");

  return context.sync().then(function () {
    // Access the text of the document's body.
    var text = body.text;

    // Do something with the text.
    console.log("Text from the active document: " + text);
  });
}).catch(function (error) {
  console.log(error);
});

© www.soinside.com 2019 - 2024. All rights reserved.