Page 1 of 1

range class in docx4j ?

PostPosted: Wed Mar 14, 2018 8:41 pm
by gosavi_pankaj
In Jacob library, Range class is used for formating content in word document. Is there any class which serves the same functionality in docx4j?
Thanks In Advance !!

Re: range class in docx4j ?

PostPosted: Thu Mar 15, 2018 7:23 am
by jason
Sorry, no.

In docx4j, JAXB objects represent the XML. So, a given w:p has a w:pPr object you use for formatting; same for w:r (it w:rPr). To alter the document, you manipulate the JAXB objects.

Suppose you have <w:r><w:t>The cat sat on the mat</w:t></w:r> and you want to make the word "cat" bold. In this case you'd have to split the sentence into three runs (the second containing "cat"), in order to embolden just that.

It would be possible to implement a https://en.wikipedia.org/wiki/Piece_table but then you'd have to route all changes through that to keep it up to date (or re-build it whenever you've made a change which bypasses it).

There hasn't been much demand for range from docx4j users over the last 10 years, but it would be interesting to have!

You might share more about your use case? (I guess converting VBA code is one, and building an editor around docx4j is another...)

Re: range class in docx4j ?

PostPosted: Wed Mar 28, 2018 11:31 pm
by gosavi_pankaj
Hi Jason,
Thanks for your reply. I implemented Range class by extending R class. I am able to modify text in of a <w:r>text</w:r> tags. But how can i set start and end point? My particular use case is actually i am trying to replace jacob library with docx4j. But i am not able to get exact implementation for range class. If it can be implemented, can help to achieve this purpose.