简体   繁体   English

Delphi-使Word文档保持重点

[英]Delphi - Keeping Word Document Focused

I have run into an interesting problem with the current application I'm working on in Delphi. 我在Delphi中正在使用的当前应用程序遇到了一个有趣的问题。 The problem is that in certain circumstances the ActiveDocument of our TWordApplication can be changed before the document is completed. 问题在于,在某些情况下,我们的TWordApplication的ActiveDocument可以在文档完成之前进行更改。

I have a TWordApplication (WordApp) and a TWordDocument (WordDoc) which are initialised as below: 我有一个TWordApplication(WordApp)和TWordDocument(WordDoc),它们的初始化如下:

WordApp.Connect;
WordApp.Documents.Add(Template, EmptyParam, EmptyParam, EmptyParam);
WordApp.ChangeFileOpenDirectory(jdir);
WordDoc.ConnectTo(WordApp.ActiveDocument);

Mostly I then update some bookmarks or insert text from a number of templates: 然后,通常我会更新一些书签或从许多模板中插入文本:

Range := '';
convert := msoFalse;
LinkFile := msoFalse;
Attach := msoFalse;
WordApp.Selection.InsertFile(Template, Range, Convert, LinkFIle, Attach);

In one workflow the creation of the document is interrupted by the creation of a second document. 在一个工作流程中,第二个文档的创建中断了文档的创建。 If this document is not closed after saving then it "steals" focus from the original. 如果保存后未关闭此文档,则它将“窃取”原始文档的焦点。 I think that it is legitimate that the user shouldn't need to remember to close down the second document. 我认为用户不需要记住关闭第二个文档是合法的。

What I want to do is either switch the focus of WordApp to WordDoc or alternatively use WordDoc directly for the InsertFile - but this doesn't seem to be an option. 我想做的就是将WordApp的焦点切换到WordDoc,或者直接将WordDoc用于InsertFile-但这似乎不是一个选择。

(There is a third option where I collate the required data for the second document before I create the first document, but that will require a change in application logic.) (第三个选项是创建第一个文档之前 ,我整理第二个文档所需的数据,但这将需要更改应用程序逻辑。)

Any help? 有什么帮助吗?

最后,我重写了逻辑以在工作流中更早地准备第二个文档,这意味着我可以不间断地编译最终文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM