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

The file ole-word-demo-3.doc is located in the folder in which I've stored the above perl script, and executed it.Well no ole-word-demo-3.txt file gets created in that folder at all.What could be the problem?

When I test this out, I get an error message indicating that the ole-word-demo-3.doc file cannot be found. If I hard code the location of the document as:

$inf="C:\\some_dir\\ole-word-demo-3.doc"; $outf="C:\\some_dir\\ole-word-demo-3.txt";
then the program works to open the specified .doc file and creates the text file. As for the rest of your task, I hope some other Monk will have some insight.

Replies are listed 'Best First'.
Re: Re: Re: Win32::OLE for MS-Word
by perl_seeker (Scribe) on Jun 13, 2003 at 09:41 UTC
    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.
      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?