为了账号安全,请及时绑定邮箱和手机立即绑定

微软词自动化

微软词自动化

C#
慕哥6287543 2021-12-25 18:31:48
我们有一个 UWP 应用程序,我们希望有以下场景:用文档打开 Microsoft Word编辑文件关闭文档并获取数据到我们的应用程序。我们有一个 Silverlight 应用程序,它使用下面的代码并很好地解决了问题。我们可以在 UWP 中做类似的事情吗?以编程方式打开 Word 并等待实例关闭。private void SetupWordInstance(bool visible = true)    {        if (AutomationFactory.IsAvailable)        {            _wordApp = null;            try            {                _wordApp = AutomationFactory.CreateObject("Word.Application");                _wordVersion = _wordApp.Version;            }            catch            {                try                {                    _wordApp = AutomationFactory.CreateObject("Word.Application");                    _wordVersion = _wordApp.Version;                }                catch (Exception)                {                    Utils.ShowMessage(Resource.MissingWordApplicationErrorMessage);                }            }            if (_wordApp != null)            {                AutomationEvent beforeCloseEvent = AutomationFactory.GetEvent(_wordApp, "DocumentBeforeClose");                beforeCloseEvent.AddEventHandler(new BeforeCloseAppDelegate(BeforeCloseApp));                AutomationEvent quitEvent = AutomationFactory.GetEvent(_wordApp, "Quit");                quitEvent.AddEventHandler(new QuitAppDelegate(QuitApp));                if (visible)                {                    _wordApp.Visible = true;                    _wordApp.Activate();                    FocusWordInstance();                }            }        }        else        {            Utils.ShowMessage(Resource.MissingAutomationErrorMessage);        }    }
查看完整描述

1 回答

?
桃花长相依

TA贡献1860条经验 获得超8个赞

有可能它可以通过微软提供的称为桌面桥接的技术进行对应。这是一个解释。很简单,就是提取UWP中没有的Windows桌面功能,和应用程序一起提供。

Docs/Windows/UWP/Develop/Porting apps to Windows 10/Desktop Bridge

以下是使用 Excel 时的示例。

桌面应用程序桥接到 UWP 示例

UWP 调用 Office Interop API

Windows 应用程序打包项目示例

Excel.Interop

由于Word API的定义如下,看来可以如上使用。

Microsoft. Office. Interop. Word 命名空间


查看完整回答
反对 回复 2021-12-25
  • 1 回答
  • 0 关注
  • 180 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号