c# Outlook 插件强制将光标移动到电子邮件正文的末尾
c# Outlook addin forcibly move the cursor to the end of email body
我正在以编程方式向电子邮件正文添加 table。我想在插入后将光标移动到 table 下方。我已经尝试 SendKeys.Send("{PGDN 10}") 并取得了一些成功,但我并不认为这是最好的方法。
有没有其他方法可以强制将光标向下移动到电子邮件正文的末尾?
办公室模型允许您在有权访问 MailItem 对象的情况下获取 WordEditor 对象。一旦有了 WordEditor 对象,就可以执行 Range 和 select 将光标放在文档中的特定位置。可能有更简单的方法,但这是一个简单的示例。
var editor = oMailItem.GetInspector.WordEditor;
editor.Range(1,1).Select();
编辑
如果您想将光标设置到正文中签名前的最后一个位置,您可以像下面的示例那样做。
var originalBody = oMailItem.HTMLBody;
oMailItem.HTMLBody = newBodyHTMLStringCompiled;
var wordDocument = oMailItem.GetInspector.WordEditor;
var endingPosition = wordDocument.Content.End;
// This will append the original signature
oMailItem.HTMLBody += originalBody;
// Set the range for the cursor
wordDocument.Range(endingPosition, endingPosition).Select();
我正在以编程方式向电子邮件正文添加 table。我想在插入后将光标移动到 table 下方。我已经尝试 SendKeys.Send("{PGDN 10}") 并取得了一些成功,但我并不认为这是最好的方法。
有没有其他方法可以强制将光标向下移动到电子邮件正文的末尾?
办公室模型允许您在有权访问 MailItem 对象的情况下获取 WordEditor 对象。一旦有了 WordEditor 对象,就可以执行 Range 和 select 将光标放在文档中的特定位置。可能有更简单的方法,但这是一个简单的示例。
var editor = oMailItem.GetInspector.WordEditor;
editor.Range(1,1).Select();
编辑
如果您想将光标设置到正文中签名前的最后一个位置,您可以像下面的示例那样做。
var originalBody = oMailItem.HTMLBody;
oMailItem.HTMLBody = newBodyHTMLStringCompiled;
var wordDocument = oMailItem.GetInspector.WordEditor;
var endingPosition = wordDocument.Content.End;
// This will append the original signature
oMailItem.HTMLBody += originalBody;
// Set the range for the cursor
wordDocument.Range(endingPosition, endingPosition).Select();