0: # I ran into this problem today and found some helpful code snippets here.
1: # However, I use Word 97 and there is a bug in the program which prevented
2: # files from being saved. I found the workaround in the ActiveState
3: # documentation. I thought people might find the code snippet helpful:
4:
5: ###############################
6: # Convert incoming word file to plain text
7: # USAGE: a full path file name needs to be provided
8: # eg c:\\dir\\file.doc
9:
10: use constant TRUE => 1;
11: use constant FALSE => 0;
12:
13: sub WordToText
14: {
15: my( $infile, $outfile) = @_;
16:
17: use Win32::OLE qw(in with);
18: use Win32::OLE::Const 'Microsoft Word';
19: $Win32::OLE::Warn = 3; # die on errors...
20: my $Word = Win32::OLE->GetActiveObject('Word.Application')
21: || Win32::OLE->new('Word.Application', 'Quit');
22:
23: my $WordFile = $Word->Documents->Open("$infile");
24: if(!$WordFile)
25: {
26: print "WordToText did not create WordFile object\n";
27: undef $Word;
28: return FALSE;
29: }
30:
31: $Word->{Visible} = FALSE;
32: $Word->WordBasic->FileSaveAs( $outfile, 2); # '2' is text
33: $WordFile->Close( );
34:
35: undef $WordFile;
36: undef $Word;
37:
38: return TRUE;
39: }
In reply to Convert MSWord to Text by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |