Is there a way to get the paragraph number using office word js api from the range object or the paragraph itself?

170 Views Asked by At

Can someone please let me know if there is any way that I could retrieve the paragraph number from a paragraph or the range object using office word js api? Working on implementing selections based on data that I get from a back end service, which provides both paragraph numbers and offsets. But, the paragraph numbers seem to be off by the cumulative number of table rows found in the document.

2

There are 2 best solutions below

2
On

Currently there is no office js api to retrieve the paragraph number from a paragraph or the range object. But I think you can get all of the paragraphs and iterate everyone to set the index number to every paragraph. Thus, you could calculate any paragraph number.

0
On

I’m currently gathering all the paragraph objects up front and adding ranges to each one. It does not take long, even with hundreds of pages. To avoid the table cells (each of which is also a paragraph), there is a property that indicates which paragraphs are in tables.