in reply to Re: Re: Win32::OLE for MS-Word
in thread Win32::OLE for MS-Word

Yes! It works now and "ole-word-demo-3.txt" gets created.
The Word formatting characters also appear as unreadable
stuff in the .txt file though, I suppose they can be
stripped off.
For doing the reverse I guess we need to
replace "wdFormatText" by "wdFormatDocument" in this
statement:
$doc->SaveAs( { FileName => $outfile, FileFormat =>wdFormatText
However I'm not familiar with the Word constants, so I'm
not sure about the rest of the statements:(
What are the other changes we need to make to this code?
Thanks in advance.

Replies are listed 'Best First'.
Re: Re: Re: Re: Win32::OLE for MS-Word
by WhiteBird (Hermit) on Jun 13, 2003 at 15:20 UTC
    You might want to look at adding the following after your require statement:

    use Win32::OLE::Const 'Microsoft Word';

    And then, changing this line:
    $doc->SaveAs( { FileName => $outfile, FileFormat => $wdFormatText});

    To:

    $word->WordBasic->FileSaveAs("$outfile", wdFormatText);

    This will remove the extra characters in the text file. As far as re-saving the document and restoring the formatting, that is another question altogether. Have you read the documentation on OLE? There's helpful information at Active State. Do a search there for all of ActiveSite on OLE as well. While there's not alot of easy to find info out there, doing a web search on "OLE" and "Perl" and "Word" will find some useful pieces for your puzzle. David Roth has a couple of excellent books out there for reference.

    Also, have you tried resaving your converted file back into Word yet and has that worked? What's the end goal for this snippet?