[英]C# Microsoft Word automation Microsoft.Office.Interop.Word
[英]Microsoft word automation
我們有一個UWP應用程序,我們希望有以下情形:
我們有一個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);
}
}
它可能與Microsoft提供的稱為Desktop Bridge的技術相對應。 這是一個解釋。 輕松提取UWP中不可用的Windows桌面功能,並將其與應用程序一起提供。
Docs / Windows / UWP / Develop / Porting apps to Windows 10 / Desktop Bridge
以下是使用Excel時的示例。
由於Word API的定義在下面,因此似乎可以如上使用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.