仅获取当前可见的文本

时间:2019-03-06 11:21:21

标签: ms-word office-js

我知道我可以使用context.document.body.getOoxml()来获取文档的整个正文,而可以使用context.document.getSelection()来获取当前的选择,但是我找不到一种方法来确定当前屏幕上的内容和未屏幕上的内容...

Word Office JS API中是否有一种方法只能检索屏幕上当前显示的内容?

1 个答案:

答案 0 :(得分:1)

There isn't a solution for this. The way some of the JavaScript libraries in web pages are able figure out this problem is through the view port.

Example here: https://www.customd.com/articles/13/checking-if-an-element-is-visible-on-screen-using-jquery

See another helpful SO answer here: Get the browser viewport dimensions with JavaScript

Now - Word however uses HTML as a way of formatting - and not as a way of directly displaying things. So even if you could run the same library on the HTML - it wouldn't have the same context.

The best you could do is to get the height of the visible space (which should be the same height as your add-in frame) and attempt to do some mapping. You would have some weird edge cases though, like if the font-size is different, or you have a page-break in the view etc...