Sergey Vladimirov wrote:
> 
> On Fri, Jul 22, 2011 at 1:23 PM, gipsy <[email protected]> wrote:
>> 1) Is there any way to get the bookmarks from a ".doc"
> Yes, there is a new API in night builds of 3.8-beta4 to access
> HWPFDocument bookmarks (i.e. document.getBookmarks()). Currently there
> are name, start and end offsets (in respect to overall document
> range). Please, let me know if you need to extract additional
> properties (like disabled autonumbering) or need additional API
> methods like getRange().
> 
>> 2) If not - how is it possible to import a ".doc" and work with an
>> XWPFDocument?
> there is no such way yet, AFAIK, but contributions are always welcomed :)
> 

Hello, I was wondering about best practices when using the Bookmark class. 
I have a document with many bookmarks, that I need to replace with values. 
I have been able to load my "template" document, retrieve all the bookmarks,
and begin to replace values.  All of the bookmarks in my document are just
empty placeholders.  Generalized code snippet below:

Bookmarks bs = doc.getBookmarks();
Bookmark b = bs.getBookmark(i);
int start = b.getStart();
int end = b.getEnd();
range = new Range(start, end, doc);
range.insertAfter("Text I want to put into bookmark location");

The problem is that the document range becomes unstable after I do a couple
range.insertAfter commands.  The start and end of each bookmark is offset by
the amount of characters I have inserted.  This is a big problem when I try
to insert text into a bookmark near the beginning of a document, after I
have already inserted text later in the document.  Maybe I should not be
using the "Range" in this situation?  Any guidance would be appreciated.

--
View this message in context: 
http://apache-poi.1045710.n5.nabble.com/1-need-bookmarks-from-doc-OR-2-import-a-doc-and-work-with-a-XWPFDocument-tp4622377p4774621.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