Firstly, no, this code will not work for .doc files. POI is able to support
both file types - binary (.doc) and OOXML (.docx) - bt it uses two different
code bases to support them. The example code is targeted at the OOXML file
format so you can only use it with .docx files. There is an example on the
list showing how to work with .doc files but that is not my code. If you
search through the posts on the list, I am confident you will find it. I can
try to put together an example from memory but cannot promise when this will
be.

Secondly, it will not replace the text you have at the bookmark positions;
it can only insert text into the document either immediately in front or
behind of the bookmarked text. If you want the code to replace the text at
the bookmarks position then it is up to you to modify the example so that it
performs in this way. I think that everything you need to see is there; all
you need to do is

1. Get the node for the bookmaerkStart tag.
2. Iterate along the nodes until you find the bookmarkEnd tag. Remove these
unwanted nodes from the document as you go.
3. Once you hit the bookmarkEnd tag, create a new run to hold the text you
wish to insert into place.
4. Insert that into the document immediately in front of the bookmarkEnd
tag.

Dig around in the DCOXTest class and you should see how to step through the
nodes, how to find out which node you are dealing with, etc. I will take a
look at the code you attached to your last message and get back to you as
soon as possible.

I will try running the code to recover bookmarks against your document -
thanks for that by the way - and let you know whether it works for tables.
It should and I hope it does because I do already know it will insert text
at bookmarks within table cells. Again, will post to this thread.

Yours

Mark B

--
View this message in context: 
http://apache-poi.1045710.n5.nabble.com/How-to-read-the-value-of-bookmarks-docx-tp5710184p5710245.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to