I’m using Aspose Words Java.
I need to associate metadata (some string) with each mail merge field in a document, such that the post-mailmerge substituted text still has the metadata available.
I was mostly able to get this to work by attaching a bookmark to each mail merge field, where the name of each bookmark is the metadata I want to persist. After the mail merge, the substituted text is still located inside of the bookmark. So I can extract out the metadata by looking at the name of each bookmark.
However, as a part of the mail merge certain portions of the document are duplicated (we use a library called Sablon which supports for loops in Word documents), which causes there to be duplicate bookmark with the same ID.
When there are bookmarks with duplicate IDs
doc.getRange().getBookmarks() no longer works properly. It considers all data between the start of the first copy of the duplicated bookmark and the end of the last copy of the duplicated bookmark to be part of one bookmark.
Not sure how to proceed. I also tried using editable ranges, but those have the same problem with duplicate IDs. All I really need is someway of wrapping the mail merge field in another node, and setting an attribute on this parent node.