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

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