Hi, Today I updated trunk code, so your example should work. Please also notice new method replaceText(String, boolean) that can help to replace bookmark text without search-and-replace.
-- Sergey Vladimirov On Tue, Sep 6, 2011 at 6:38 PM, joejoe <storc...@gmail.com> wrote: > > Sergey Vladimirov wrote: >> >> On Fri, Jul 22, 2011 at 1:23 PM, gipsy <spam.gi...@gmail.com> 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. --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@poi.apache.org For additional commands, e-mail: user-h...@poi.apache.org