Doing a 'mail merge' with RTF files (aka RTF templates)

T

Tony

I have a MS Word document with mail merge fields in it.

I've saved it as rich text format (RTF), and now I want to write a
perl program that will take this template file as input, replace the
mail merge fields with data, and then spit out a populated RTF file
for each record.

Is there a module to make this easier? I can see the mail merge fields
in the raw RTF document, but they're complex structures, and I don't
really want to learn the RTF spec in order to know what I should be
replacing in each case.

For example, if I replace the word "address" with a merge field called
"address", this is the extra code that appears in the RTF file:


}{\field{\*\fldinst { MERGEFIELD address \\* MERGEFORMAT }}{\fldrslt
{\lang1024 \'abaddress\'bb}}}{


And it's even more obscure when you have tables, and formatting etc.
I'll take a look at rtf::tokenizer, but my initial assesment is that
it's not quite what I'm after.

Any ideas?

Thanks, Tony
 
J

Jonathan Stowe

In comp.lang.perl.misc Tony said:
I have a MS Word document with mail merge fields in it.

I've saved it as rich text format (RTF), and now I want to write a
perl program that will take this template file as input, replace the
mail merge fields with data, and then spit out a populated RTF file
for each record.

Is there a module to make this easier?

I would suggest that you use a templating module such as the Template
Toolkit - there seems to be no need to be parsing the RTF for this
application.

/J\
 
T

Tony

Jonathan Stowe said:
I would suggest that you use a templating module such as the Template
Toolkit - there seems to be no need to be parsing the RTF for this
application.

/J\

Thanks for the tip Jonathan. I've looked into the Template-Toolkit,
and I think it will be useful.

Unfortunately, mail merge field codes in RTF documents aren't plain
text. So before I use the Template-Toolkit, I'll have to replace any
field codes with the [% plain text %] notation. But that's no biggy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top