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

Does anyone know if there is a module that is similar to CGI.pm, but for use with Microsof Word docuemnts or RTF files.

I'm not looking for anything with an Excel spreadsheet, just the word processor docs. I've been told about Win32::OLE, but it seems that that is for taking control of an application, whereas I'm just looking for something to generate and parse Word docs.

Any help would be greatly appreciated.

Replies are listed 'Best First'.
(boo) Re: Microsoft Word Document modules?
by boo_radley (Parson) on Feb 24, 2001 at 00:02 UTC
    Somebody set us up the google!!
    RTF::Document
    documentation
    Code Sample from POD :
    use RTF::Document; # Document properties $rtf = new RTF::Document( { doc_page_width => '8.5in', doc_page_height => '11in' } ); $rtf->add_text( $rtf->root(), "Default text\n\n", { bold=>1, underline=>continuous }, "Bold/Underlined Text\n\n", { font_size=>'20pt', font=>$fCourier, color_foreground=>$cRed }, "Bigger, Red and Monospaced.\n\n", { style_default=>paragraph }, { style_default=>character }, "This is ", [ { style=>$sGreen }, "green" ], " styled.\n\n"
    but, it doesn't appear to be in CPAN, so it could set your computer on fire, or sell guns to kids. If you find a pile of ashes where your computer was, or if a 5 year old shoots you, don't blame me...
    Actually, it looks pretty complete. But I had to throw in the warning. Update 28MAR2001 this module's in CPAN now. Its documentation still appears to be missing.
Re: Microsoft Word Document modules?
by Tyke (Pilgrim) on Feb 26, 2001 at 16:45 UTC
    If you really want to write MS-Word docs rather then RTF (see boo_radley above) then you've got two possibilities:
    1. Reverse engineer the current MS-Word format and write your own code to generate this format. Apart from the fact that MS would be really thrilled about this, be aware that the format changes regularly. Yeah, I think we agree that this is a non-starter! So that leaves
    2. Use OLE. What you'd need to do is to call VB functions to write the document for you. This really isn't all that difficult, if
      • you have all the help for MS Word VB on your system;
      • you use the object browser in the VB editor (accessed by (Tools->Macros->Visual Basic) and then (View->Object Browser)) to find methods, attributes and constant values.

    I really don't know of any other options.

    Update Oh, I forgot to say that the second solution isn't very portable ;)