Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I open a Word document read-only from Perl?

Tags:

ms-word

perl

ole

Is there any method within Perl which would allow me to get the object in a read only mode, so as to avoid the dialog that pops up if the file is locked by another user?

$document = Win32::OLE->GetObject("$docFile")
    or die "can't open $docFile";
like image 287
EvilTeach Avatar asked Sep 24 '09 15:09

EvilTeach


1 Answers

That's because you're doing it wrong. GetObject just opens an object with the default behavior. You should create the Word.Application object:

 my $word = Win32::OLE->new( 'Word.Application' );

Then use the Documents collection Open method with the named parameter ReadOnly. Like so:

 $doc = $word->Documents->Open( { FileName => $document_path,
                                , ReadOnly => 1
                                } );

Read http://msdn.microsoft.com/en-us/library/bb216319.aspx for the syntax for Documents.Open

like image 156
Axeman Avatar answered Sep 28 '22 06:09

Axeman