我們有一個(gè) UWP 應(yīng)用程序,我們希望有以下場(chǎng)景:用文檔打開 Microsoft Word編輯文件關(guān)閉文檔并獲取數(shù)據(jù)到我們的應(yīng)用程序。我們有一個(gè) Silverlight 應(yīng)用程序,它使用下面的代碼并很好地解決了問(wèn)題。我們可以在 UWP 中做類似的事情嗎?以編程方式打開 Word 并等待實(shí)例關(guān)閉。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 回答

桃花長(zhǎng)相依
TA貢獻(xiàn)1860條經(jīng)驗(yàn) 獲得超8個(gè)贊
有可能它可以通過(guò)微軟提供的稱為桌面橋接的技術(shù)進(jìn)行對(duì)應(yīng)。這是一個(gè)解釋。很簡(jiǎn)單,就是提取UWP中沒(méi)有的Windows桌面功能,和應(yīng)用程序一起提供。
Docs/Windows/UWP/Develop/Porting apps to Windows 10/Desktop Bridge
以下是使用 Excel 時(shí)的示例。
UWP 調(diào)用 Office Interop API
Windows 應(yīng)用程序打包項(xiàng)目示例
由于Word API的定義如下,看來(lái)可以如上使用。
Microsoft. Office. Interop. Word 命名空間
- 1 回答
- 0 關(guān)注
- 172 瀏覽
添加回答
舉報(bào)
0/150
提交
取消