我正在使用自动化在 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 );
但用户可以在打开的文档中关闭阅读模式:
在过程中如何处理这个OnQuit
事件DocumentClose
?在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;