【发布时间】:2015-10-06 23:19:15
【问题描述】:
我正在使用自动化在 Word 中打开文档。有时我需要在阅读模式下打开文档:
var
WordDocument: _Document;
WA: TWordApplication;
begin
WA := TWordApplication.Create( nil );
WA.OnQuit := DocumentClose;
WA.Connect;
WordDocument := Wa.Documents.Open( FileName, EmptyParam, true {ReadOnly}, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam );
但用户可以在打开的文档中关闭阅读模式:
如何在过程 DocumentClose 中的 OnQuit 事件中处理此问题?
在DocumentClose 我想知道文档是否处于读取模式。
我没有任何解决方案,因为我没有足够的经验。 所以,我需要你的建议,关于它的建议。对不起我的英语,如果我必须添加更多信息,请告诉我。谢谢
更新
我试图阅读保护类型,但它总是返回第一种情况。因此,当以 ReadOnly 方式打开的文档不受 wdAllowOnlyReading 保护时。有些文件可以用密码保护,但没有问题。
const
wdAllowOnlyReading: Longword = $00000003;
wdNoProtection: Longword = $ffffffff;
var
ProtectionType: TOleEnum;
begin
ProtectionType := WordDocument.ProtectionType;
case ProtectionType of
wdNoProtection : Showmessage('NoProtection');
wdAllowOnlyReading: Showmessage('ReadOnly');
end;
end;
【问题讨论】:
-
我想您可以尝试在打开文件之前将文件临时设置为只读,但这似乎是一种草率的解决方法。
-
也许this link 有解决办法。
-
我以为你在自动化。在哪种情况下,用户如何参与?
-
@DavidHeffernan 当用户刚刚打开 ReadOnly 文档时 - 当用户打开 ReadOnly 文档时不需要操作。然后在 MSWord 中选择 View-Edit Document 然后我需要在我的代码中执行一些操作
-
用户可以做任何他们喜欢的事情。毕竟是他们的电脑。如果他们愿意,他们可以直接杀死 Word。在完成之前关闭文档。只需要求用户不要管它。或者更好的是,甚至不向他们展示文档
标签: delphi ms-word activex ole-automation