WPF应用程序中的Word文档控制自动化 [英] Word Document Control Automation in WPF Application

查看:81
本文介绍了WPF应用程序中的Word文档控制自动化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

Word文档控件嵌入在WPF应用程序中,其内容可见,可供编辑和阅读。我正在尝试自动执行此控件,但面临如下所述的问题

A word document control is embedded in WPF application and its content is visible for editing and reading. I am trying to automate this control but facing issue as elucidated below

我正在利用UI Automation API在编码的UI测试中自动执行WPF控制,并使代码自动执行以上场景,如下所示

I am making use of UI Automation API to automate WPF control in Coded UI Test and code to automate above scenario as follows

AutomationElement applicationElement =<在此处分配的应用程序元素>

AutomationElement wordElement = applicationElement.FindFirst(TreeScope。后代,新的System.Windows.Automation.PropertyCondition(AutomationElement.NameProperty," Microsoft Word Document"));

Object objWordCtrl = wordElement;

Microsoft.office.Interop.Word.Document worddoc =(Microsoft.office.interop.Word.Document)wordElement;

但是我得到了预测错误,说无法将"System.Windows.Automation.AutomationElement"类型的对象强制转换为"Microsoft.office.Interop.word.Document"

你可以帮我解决上面的错误,这样我就可以利用这个词用于处理Word文档的API。

Can you please help me on above error so that i can make use of word API to act on word document.

推荐答案

我们非常感谢任何帮助。

Any help would be really appreciated.


这篇关于WPF应用程序中的Word文档控制自动化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆