Free Support Forum - aspose.com

Duplicating Data in Document using Patterns

We use Aspose Words for Java to allow our users to create templates used for printing. I have ran into an area where I could use some help.

In a document, we use ReplaceEvaluators to replace text with data, tables, and images. So if the following text was in the document:
Document prepared by <{preparer name}>

We would replace <{preparer name}> with a value from the database. Here is the problem I would like to solve.

We would like a user to create a template that shows all users in the database. For example, the original document would look like this:

Here is a list of users in the database:

First Name: <{firstName}>
Last Name: <{lastName}>



I would like to clone lines 2 and 3 in the document for each user that exists. So, if there are 3 users in the system, I would like the document to look like this:
First Name: <{firstName1}>
Last Name: <{lastName1}>

First Name: <{firstName2}>

Last Name: <{lastName2}>

First Name: <{firstName3}>

Last Name: <{lastName3}>

and then do the replacing (which is already implemented in our system).

I have a Pattern to do the replacing, but I receive the error:
"java.lang.UnsupportedOperationException: The match includes one or more special or break characters and cannot be replaced."

Are there any other ideas on how to accomplish what I am looking for? Thanks in advance.

It seems that the pattern you are using does not exclude special characters like paragraph breaks and such from match. Try to improve your pattern to include only alphanumeric characters in the name search.

Also, the task like this are best to be solved using so called MailMerge process which is well described in our documentation. Please check MailMerge related articles in our Wiki. Maybe you will find it an attractive alternative to your current process.

Best regards,