2

I know I can get the whole body of a document with context.document.body.getOoxml() and the current selection with context.document.getSelection(), however I can't find a way to establish what is currently on screen and what is not...

Is there a method in the Word Office JS api to retrieve only the content currently displayed on the screen?

Cindy Meister
  • 25,071
  • 21
  • 34
  • 43
Leo
  • 5,013
  • 1
  • 28
  • 65
  • 2
    Even the COM APIs don't have a method or property for this, if you mean visible in the Word application window (as opposed to being hidden in the document)... – Cindy Meister Mar 06 '19 at 11:49

1 Answers1

0

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

Mavi Domates
  • 4,262
  • 2
  • 26
  • 45
  • 1
    FWIW Word does not use HTML for formatting or anything else. It can only import/export the format using a converter. – Cindy Meister Mar 06 '19 at 11:56
  • In this context Word uses HTML for formatting / converter or not - that doesn't matter. You can inject styled HTML using a Web add-in and Word would display it as it should be displayed on an HTML page. The article solutions however require a browser and access to viewport. Since Word doesn't have this functionality - there isn't a solution for this - please read the first sentence. – Mavi Domates Mar 06 '19 at 16:20