Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Perl + MS Word

posted by ziggy on 2001.03.06 21:56   Printer-friendly
SJ writes "Does anybody know of any modules which allow a perl program to create an MS Word formatted file? Any help would be much appreciated. Thanks."

Good question. There's Win32::OLE for Windows users, but a brief spin around CPAN is finding little else...

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • How about creating a richtext file with RTF::Document? If a .doc format is desired you could then use Win32::Ole to convert the .rtf into a .doc using word. Christian
  • Well, I should go with Win32::Ole all the way. I have been using it full-blown with M$ Excel and it worked great. BTW why converting a RTF file? Word opens the file fine, any receiver (e.g. collegue) can use the document straight away
  • I'm having a lot of success with two methods:

    First, MS-Word 98/2k will read HTML (UGH!) seamlessly. The trick is not to use XHTML or exercise too much of the HTML 4.0 spec. Just really basic (and non-conforming) HTML 3.2 converts nicely. (isn't that sad?) Headers become proper document headers (H1, H2, H3) and all of the text markup seems to be making it in okay, including tables to some extent.

    The RTF suggestion is a good one. I'm submitting text to my publisher in RTF which was converted from an X

  • A friend of mine showed me this trick, if you change your output file.txt to file.xls, even though it's in text format, Excel will see the xls extension, realize it's a text file (which it already knows how to convert) and open the file without any problems. This may work for your situation (change the extension to .doc instead of .xls) if you don't have an fancy markup, but if you do have some fancy markup you may be better off with the HTML that someone else suggested.
  • OK so the docs start out in XML. If you had a bit more flexibility about the input format I would have mentioned that there are at several RTF modules on CPAN including at least two separate pod2rtf converters:

    Module that have "rtf" []

    Perhaps one of them could have helped a situation in which .pod was an input format choice.

  • It is entirely possible to create Word-documents by using Win32::OLE, but it requires Perl to run on a Win32-machine with Office installed and there is a bit of voodo involved in figuring out how to translate what's in the manuals for Visual Basic into valid syntax for Win32::OLE. Another approach is therefore to generate Visual Basic code in text format from your Perl-script. Then fire up word and let word run the macro that you just generated. For example, your Perl-program can generate the output: