in reply to convert text to word
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......
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: convert text to word
by Anonymous Monk on Feb 06, 2003 at 16:21 UTC | |
by BrowserUk (Patriarch) on Feb 06, 2003 at 17:36 UTC |