Why bother, Word will open text files? Why turn an elegant compact file into a bloated proprietary M$ *.doc file. If you make it a Word 2000+ file you will have turned a file that can be read by anyone into a file that can only be read by people who have Word 2000 or later installed. Wo betide those of us who have not bought a copy of Word since Word 95 which was about the last time a useful feature was added IMHO.

You can probably do it with Win32::OLE if you really want to, but why on earth would you bother? Rather like taking a Perl and turning it into a swine......

Update

For the record here is how to add text to a new word document using Win32::OLE. I will leave it as an exercise for the reader as to how to read the text file in (see perlman:open)....

use Win32::OLE; # check if Word exists and is running my $word = Win32::OLE->GetActiveObject('Word.Application'); die "Word not Installed" if $@; # start Word program instance if required or die if unable to unless (defined $word) { $word = Win32::OLE->new('Word.Application', sub { $_[0]->Quit; } ) + or die 'Cannot start Word'; } # hide/show the document $word->{Visible} = 0; # Create new document my $d = $word->Documents->Add; # define selection my $s = $word->Selection; #set lines to be written to document my @lines = ( "This is a test line\n", "This is second test Line\n", "This is the third line\n", ); # add the lines of text $s->TypeText($_) for @lines; # save our object $word->WordBasic->FileSaveAs("c:\\test.doc"); # undef our object out of existance undef $word;

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print


In reply to Re: (Win32::OLE) convert text to word by tachyon
in thread convert text to word by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.