如何从 Perl 中以只读方式打开 Word 文档?

发布于 2024-08-06 13:22:05 字数 164 浏览 1 评论 0原文

Perl 中是否有任何方法可以让我以只读模式获取对象, 以避免文件被其他用户锁定时弹出的对话框?

$document = Win32::OLE->GetObject("$docFile")
    or die "can't open $docFile";

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";

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笨死的猪 2024-08-13 13:22:05

那是因为你做错了。 GetObject 仅以默认行为打开一个对象。您应该创建 Word.Application 对象:

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

然后使用带有命名参数 ReadOnlyDocuments 集合 Open 方法。像这样:

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

阅读 http://msdn.microsoft.com/en-us/ library/bb216319.aspx 了解 Documents.Open 的语法

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文