Phone number formatting

Hello All,
I am fetching data from DB2 and putting on my document using :
doc.getMailMerge().execute(resultset);

i have one phone number field which i want to format so that it will show the phone number in proper US format, something like (123) 456 7890
I tried applying all the possible formats(i found on internet) in my word template. But its not working. Is there anything special i need to do when fetching data from DB2?

I think you need to find out in what format the phone numbers are stored in your database. They are probably strings storing phone numbers in one or two different formats, like 12345678 or 123-456-78. You need to parse and reformat these strings manually before merging them into the document. This preformatting itself can take place in MergeFieldEventHandler listener.

Hope this helps,

Hi Vladimir,
We are storing the phone numbers as VARCHAR fields in database.
As per your suggestion, i tried using MergeFieldEventHandler. But i had to format the phone string in java to get it working. When you say “You need to parse and reformat these strings manually…”, do you mean the same thing? Or i need to convert the String to some kind of numeric representation and then the MergeFormat defined on the template will do the rest?

Yes, I meant formatting merge string in Java using regular expressions or some self-made string transformaton routine.