Perl - can't open file with Win32::OLE -
this question has answer here:
- convert word doc or docx files text files? 12 answers
i'm trying open .docx
file using following code:
require win32::ole; $docfile = "c:/users/me/documents/file.docx"; $word = win32::ole->getactiveobject('word.application'); unless ($word) { $word = win32::ole->new('word.application', sub {$_[0]->quit;}) or die "oops\n"; } $word->{visible} = 1; $file = $word->documents->open($docfile); $file->printout(); $file->close(); $word->quit();
but following error:
ole exception "microsoft word":
sorry, couldn’t find file. possible moved, renamed or deleted? (c://users/me/documents/...)
how can fix this? why add // path? (needless say, file exist in system , correct path).
thanks!
i suggest use canonpath
file::spec::function
normalise file path , change path separators backslashes
like this
use strict; use warnings 'all'; use win32::ole; use file::spec::functions 'canonpath'; $docfile = "c:/users/me/documents/file.docx"; $word = win32::ole->getactiveobject('word.application') or die; $word->{visible} = 1; $file = $word->documents->open(canonpath($docfile)) or die; $file->printout; $file->close; $word->quit;
Comments
Post a Comment