We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Aspose.Words java - Mail Merege

Our application creates word documents from templates. We were using a third party solution for this. We have decided to move to Aspose.Words java for some reasons. We are finding a problem with respect to existing templates format.
The existing templates use bookmarks to denote start and end of a repeating section for mail merge. But aspose uses tableStart: and tableEnd merge fields. We have hundreds of templates and manually identifing the bookmarks and modifying them to use tableStart and tableEnd merge fields is difficult. We have 2 questions.
1) Is it possilbe to programatically identify bookmarkstart and bookmarkend and then in the same place, place tableStart and tableEnd fields?
2) Can we do the repeating merge with bookmarks indicating start and end positions instead of tableStart and tableEnd

This message was posted using Page2Forum from executeWithRegions bookmark - Aspose Search Results - Aspose.com

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for your interest in Aspose.Words for java.

1. You can try using the following code to replace BookMarkStart and BookmarkEnd nodes with TableStart and TableEnd mergefields.

//Open document

Document doc = new Document("in.doc");

//Create DocumentBuilder

DocumentBuilder builder = new DocumentBuilder(doc);

String bookmarkName = "myTable";

//Create TableStart merge filed code

String startFieldCode = "MERGEFIELD TableStart:" + bookmarkName + " \\* MERGEFORMAT";

//Create TableStart merge filed value

String startFieldValue = "«TableStart:" + bookmarkName + "»";

//Create TableEnd merge filed code

String endFieldCode = "MERGEFIELD TableEnd:" + bookmarkName + " \\* MERGEFORMAT";

//Create TableEnd merge filed value

String endFieldValue = "«TableEnd:" + bookmarkName + "»";

//Move cursor to BookmarkStart

builder.moveToBookmark(bookmarkName, true, true);

//Insert TableStart field

builder.insertField(startFieldCode, startFieldValue);

//Move cursor to BookmarkEnd

builder.moveToBookmark(bookmarkName, false, false);

//Insert TableEnd field

builder.insertField(endFieldCode, endFieldValue);

//Remove bookmark



//Save document


I hope this could help you.

2. Unfortunately you can’t do the repeating merge with bookmarks.

Best regards.