这是我的情况 . 我已经制作了一个应用程序窗体,它根据用户的操作编辑Excel工作表(按钮/切换/文本框等等) .
完成编辑后,将生成新的Excel文件 .
然后我的程序选择一系列单元格并复制它 . 它去剪贴板 .
我做了多次测试(if(){} else {} /保存到.jpg /等等 . )所有内容都检查为true .
我不想附上我的照片 . 我不想保存它,即使是暂时的,然后通过保存的.jpg文件将其粘贴到正文中 . 我“只是”想要一个Ctrl V,进入我的Outlook电子邮件正文 .
这是我如何从剪贴板中获取图像(“MessageBody”在顶部被声明为公共字符串,以便我可以通过不同的区域调用它):
public void ReadData()
{
Excel excel = new Excel(@"E:\c#\Project#XX\Resources\TEST.xlsx", 1);
excel.CopyRange(0, 0, 32, 12);
IDataObject iData = Clipboard.GetDataObject();
if (iData.GetDataPresent(DataFormats.Bitmap))
{
Bitmap MessageBody = (iData.GetData(DataFormats.Bitmap, true) as Bitmap);
//pbx.Image = Image;
//image.Save(@"E:\c#\Project#XX\Resources\bitmap1.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
//MessageBody = image;
}
excel.Close();
excel.Quit();
}
这是我的消息构建代码:
private void flatCustButton013_Click(object sender, EventArgs e)
{
ReadData();
string MessageSubject = $"SomeSubject";
Outlook.MailItem newMail = (Outlook.MailItem)application.CreateItem(Outlook.OlItemType.olMailItem);
newMail.Subject = MessageSubject;
newMail.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;
MessageHTMLBody = "<html><body>SomeText.<img src="cid:MessageBody"</img></body></html>";
newMail.HTMLBody = MessageHTMLBody;
//newMail.Body = System.Windows.Input.ApplicationCommands.Paste;
//newMail.Display(false);
//newMail.BodyFormat = Outlook.OlBodyFormat.olFormatHTML; ;
//newMail.HTMLBody = System.Windows.Input.ApplicationCommands.Paste;
//newMail.Body = MessageBody;
newMail.To = ToAddress;
newMail.SentOnBehalfOfName = FromAddress;
newMail.CC = CcAddress;
newMail.BCC = BccAddress;
//System.Windows.Input.ApplicationCommands.Paste;
//wrdEdit = application._Inspector.WordEditor
newMail.Send();
}
在以前的版本中,人们必须打开Excel文件,手动更改单元格,然后单击按钮(在VB中使用宏) . 它会打开一个Outlook eMail项目(显示:true),已经粘贴了图像,然后只需要点击“发送”即可 .
我的2.0版本只需单击“发送//生成的Excel工作表//”按钮即可自动完成此操作 .
这是VB中的宏代码:
Sub SendMail()
Dim Messager As New Outlook.Application
Dim Mail As Outlook.MailItem
Dim WrdEdit
Range("my_range").CopyPicture
Set Messager = New Outlook.Application
Set Mail = Messager.CreateItem(olMailItem)
With Mail
.To = "some folks"
.CC = "some folks"
'.BCC = ""
.Subject = "SomeSubject"
.Display
.HTMLBody = Mess + .HTMLBody
End With
Set WrdEdit = Messager.ActiveInspector.WordEditor
WrdEdit.Application.Selection.Paste
Set WrdEdit = Nothing
Set Messager = Nothing
Set Mail = Nothing
ActiveWorkbook.Close SaveChanges:=False
End Sub
但我不明白为什么我会通过检查员(我不知道),如果我成功检索剪贴板图像 .
1 回答
我找到了一种方法,将本地保存文件中的附件添加到邮件中,并使用HTML将其显示在正文中 .
像这样:
“http://schemas.microsoft.com/mapi/proptag/0x3712001E”代码在这里:http://www.outlookcode.com/codedetail.aspx?id=1915 .
它有效 .
但是,我真的不喜欢在我的代码中使用网址,还有其他方法吗?
而且,它看起来像我放入我的'imagecid'字符串中的任何内容都没有任何变化 .
我正在努力理解我对代码的所作所为,而不仅仅是让它按原样运行 .
看起来我需要Office的一些授权来处理应用程序?尤其是当我想将图像粘贴到一个正文中时(它可以包含除了像素数据之外的其他内容) .
如果我不需要使用VB脚本进行自动化,我想,这是因为我必须“物理/人性化”按下Outlook中的“发送邮件”按钮?
还有其他可能性吗?我仍然使用文件粘贴在我的身体,我不能只是以编程方式按Ctrl C Ctrl V? :(