Outlook互操作-在光标位置插入字符串



我目前正在使用Outlook interop在光标位置插入一些文本。

我有一个有效的解决方案来注入电子邮件和日历主体,但我似乎找不到任何可以让我找到光标位置(焦点元素(的地方。

我正在使用CurrentItem来确保我有正确的项目,但我想知道重点是什么项目,所以在MailItem中是:body、subject、to、cc和bcc。则CalendarItem是焦点正文或标题。

有没有从CurrentItem找到键盘/光标焦点的方法?

我目前注射到身体的工作解决方案:

var outlookAsObject = Marshal.GetActiveObject("Outlook.Application");
_outlook = (Microsoft.Office.Interop.Outlook.Application) outlookAsObject;
_log.Info("Outlook Application found");
var activeElement = _outlook.ActiveInspector().CurrentItem;
_log.Info($"outlook injector: Current item is mailItem: {activeElement is 
MailItem}");
Inspector myInspector = activeElement.GetInspector;
_log.Info("outlook injector: inspector obtained");
Document wdDoc = myInspector.WordEditor;
_log.Info("outlook injector: document obtained");
var wdRng = wdDoc.Application.Selection.Range;
_log.Info($"outlook injector range is: {wdRng}");
wdRng.InsertAfter(text);
_log.Info("outlook injector: Text sent");

完成这项工作并非易事。Outlook可扩展性模型并没有提供开箱即用的信息。

最好的方法是使用Windows API来对Outlook窗口进行子类化。您也可以尝试使用辅助功能API。

最新更新