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

Discussion in 'Perl Misc' started by Tony, Aug 25, 2003.

  1. Tony

    Tony Guest

    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
    Tony, Aug 25, 2003
    #1
    1. Advertising

  2. In comp.lang.perl.misc Tony <> wrote:
    > 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\
    --
    Jonathan Stowe |
    <http://www.gellyfish.com> | This space for rent
    |
    Jonathan Stowe, Aug 25, 2003
    #2
    1. Advertising

  3. Tony

    Tony Guest

    Jonathan Stowe <> wrote in message news:<i4n2b.4$>...
    > In comp.lang.perl.misc Tony <> wrote:
    > > 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\


    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.
    Tony, Aug 27, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VB Programmer

    How to emulate Word mail merge in HTML?

    VB Programmer, May 20, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    1,131
    VB Programmer
    May 20, 2004
  2. Martin Feuersteiner
    Replies:
    0
    Views:
    2,990
    Martin Feuersteiner
    Jul 19, 2004
  3. JKop
    Replies:
    3
    Views:
    468
  4. recover
    Replies:
    2
    Views:
    802
    recover
    Jul 25, 2006
  5. Patrick
    Replies:
    0
    Views:
    326
    Patrick
    Feb 17, 2004
Loading...

Share This Page