Dan Tao
Dan Tao

Reputation: 128317

Office JavaScript API: scrolling within a document

I'm working on a side project using the Microsoft Office JavaScript APIs. I have been relying on the documentation to find my way around, but I've hit a wall trying to find something in the docs (perhaps it isn't there because it doesn't exist).

Recently I was implementing programmatic scrolling to a certain position within a Word document. I am currently using the Range.select method to accomplish this, but the scrolling behavior isn't exactly what I want: the method ensures that the document scrolls so that the range is visible, but it doesn't always end up in a consistent location relative to the viewport. I.e. sometimes the range is at the bottom of the document, sometimes it's in the middle, and sometimes it's at the top.

I'm wondering: is there a way with the Office JavaScript APIs to exert more precise control over the scroll position of the document? In my ideal world, there would be something analogous to scrollTo (but of course I can't use scrollTo directly, as my add-in cannot directly access the parent window where the document is rendered).

Upvotes: 0

Views: 1158

Answers (2)

Sagar Mistry
Sagar Mistry

Reputation: 131

am not sure scroll position of the document via Word API. But I did one thing in code to scroll to top of body when we trigger button.

context.document.body.getRange('Start').select();

Upvotes: 0

Rick Kirkham
Rick Kirkham

Reputation: 9684

I'm afraid that there isn't an API in Word.js that will control the scroll position of the document. But it is a good idea. Please suggest it at Office Developer Suggestion Box.

Upvotes: 1

Related Questions