mpolo has asked for the wisdom of the Perl Monks concerning the following question:

I have a large tab-separated text file that I was converting into an HTML file via perl to present to my boss. He, however, wants his output in Word format, but will settle for RTF.

There are a couple of CPAN modules with promising names, but no documentation. RTF::Document seems to be discontinued, though it has the advantage of having an ActiveState port for Win32. I could only find very limited documentation, though, which stressed the pre-alpha nature of said code. RTF::Generator looks really spiffy, and it's even at 1.00, but after installing it on a Linux box (no ActiveState port available), I found out that there is no POD to speak of, nor man files, so I would have to dissect the code to figure out how to use it...

Is there another way, short of wading through Microsoft's fine and well-organized RTF 1.5 specification? Thanks for any insights...

Replies are listed 'Best First'.
Re: Generating RTF Documents
by mincus (Chaplain) on May 05, 2001 at 18:49 UTC
    Here is the code to take a simple text file and insert it into a word document...
    use Win32::OLE; $App = Win32::OLE->new('Word.Application'); $App->{Visible} = 1; $document=$App->Documents->Add; open (FILE, "text.txt"); @data=<FILE>; foreach (@data) { $App->Selection->TypeText($_); } $document->{Saved}=0; $App->Quit; $document=0; $App=0;
    hope that gives you a start. Good luck!


    .mincus
    telnet://bbs.mincus.com

      Thank you!

      Not exactly an answer to the original question, but a better solution than I was contemplating! (Except that eventually the program will be living on an NT server that -- I fear -- lacks Word. But that's a minor problem...)

Re: Generating RTF Documents
by rchiav (Deacon) on May 05, 2001 at 18:26 UTC
    Well if you're on a Windows machine and it has Word on it.. and you want to do it in Word, you could use Win32::OLE to create an instance of Word. Then you'd just need to do some digging in the Word object model to figure out how to do exactly what you want to do.

    Hope this helps..
    Rich

Re: Generating RTF Documents
by providencia (Pilgrim) on May 05, 2001 at 23:23 UTC
Re: Generating RTF Documents
by rrwo (Friar) on Jul 04, 2001 at 20:13 UTC

    RTF::Generator is under construction (I'm the maniac behind it, so direct all flames about it's incompleteness to me). It's a big project, but there is some POD in some of the modules.

    There is also an RTF::Writer module which uses a different take... it has more documentation on RTF (an "RTF Cookbook") but is based on knowing how an RTF document is set up. I haven't played with it, though.

    (RTF::Generator is meant to let you concentrate on the document part, not the RTF part, and to allow plug-ins of sorts to add new features; it's also part of my diabolical scheme, um pipedream, to create a DBI-like interface that allows one to generate documents like RTF, PostScript, Word, etc. by using a plug-in driver...)

    Serously... much apologies on the module not being complete yet. I am working on it along with several other projects.