0

I'm developing an web application which allows to compare 2 docx documents. And I want to highlight similar locations in two documents. I used apache poi to process docx files. Furthermore to highlight I can set some properties in a text run. However this way works only for text run unit. So, Is there any way to highlight (ex: bold, set color...) a substring in a given paragraph in a arbitrary location ?.

thoitbk
  • 269
  • 2
  • 9
  • 21
  • 2
    I think the file format requires that everything in a CharecterRun shares the same format. Have you tried adding a new CharacterRun covering your text to highlight, then styling that? – Gagravarr Mar 30 '13 at 04:01
  • How can I add a CharacterRun from a character to another character in a paragraph without creating new paragraph like document.newParagraph(); paragraph.newRun() – thoitbk Mar 30 '13 at 06:46
  • You'd need to manipulate the character run list for a paragraph, insert a new one in the middle, delete the text from the surrounding ones, add it to the new one, then style that. I think that should work... Try it and report back! – Gagravarr Mar 30 '13 at 15:21
  • 1
    @Gagravarr is correct. That's how the file format works, and therefore how you'd do it with POI or docx4j. Some libraries may provide a higher level API for doing it. – JasonPlutext Apr 03 '13 at 20:51
  • See the answer I gave here, hope it helps: https://stackoverflow.com/questions/44242516/how-to-highlight-a-text-for-a-pargraph-in-ms-word-using-poi/49917317#49917317 – Ale Apr 19 '18 at 09:25

0 Answers0