Perl中是否有任何方法可以让我在只读模式下获取对象 以避免在文件被其他用户锁定时弹出对话框?如何从Perl中以只读方式打开Word文档?
$document = Win32::OLE->GetObject("$docFile")
or die "can't open $docFile";
Perl中是否有任何方法可以让我在只读模式下获取对象 以避免在文件被其他用户锁定时弹出对话框?如何从Perl中以只读方式打开Word文档?
$document = Win32::OLE->GetObject("$docFile")
or die "can't open $docFile";
那是因为你做错了。 GetObject
只是用默认行为打开一个对象。您应该创建Word.Application
对象:
my $word = Win32::OLE->new('Word.Application');
然后使用Documents
收集Open
方法与命名参数ReadOnly
。像这样:
$doc = $word->Documents->Open({ FileName => $document_path,
, ReadOnly => 1
});
阅读http://msdn.microsoft.com/en-us/library/bb216319.aspx的语法Documents.Open
为什么你们报$ DOCFILE? – innaM 2009-09-24 16:06:47
如果你只想要文本,你可以尝试在其上运行'antiword'或类似的东西。然而,我不确定'antiword'是否构建在Windows上。这是我在OSX和Linux上处理Word文档的首选方法。 – Telemachus 2009-09-24 17:24:31