通过C#将图片添加到powerpoint幻灯片会引发远程过程调用失败。(来自HRESULT的异常:0x800706BE)
伙计们 我这里有一段代码:通过C#将图片添加到powerpoint幻灯片会引发远程过程调用失败。(来自HRESULT的异常:0x800706BE),c#,powerpoint,office-interop,office-automation,C#,Powerpoint,Office Interop,Office Automation,伙计们 我这里有一段代码: System.Net.WebClient wc = new System.Net.WebClient(); byte[] data = wc.DownloadData(xmlTempNode.Attributes["imageurl"].Value.ToString()); MemoryStream ms = new MemoryStream(data); System.Drawing.Image img = System.Drawing.Image.FromStre
System.Net.WebClient wc = new System.Net.WebClient();
byte[] data = wc.DownloadData(xmlTempNode.Attributes["imageurl"].Value.ToString());
MemoryStream ms = new MemoryStream(data);
System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
string strImagePath = pptdirectoryPath + "\\" + currentSlide + "_" + shape.Id + ".png";
img.Save(strImagePath);
tempSlide.Shapes.AddPicture(strImagePath, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, shape.Left, shape.Top, Convert.ToInt32(xmlTempNode.Attributes["imgwidth"].Value), Convert.ToInt32(xmlTempNode.Attributes["imgheight"].Value));
shape.Delete();
tempsile.Shapes.AddPicture
适用于较小的图像,当分辨率较高时失败(此处失败意味着无限时间内未收到响应,并在刷新页面时引发异常)
异常消息:远程过程调用失败。(来自HRESULT的异常:0x800706BE)
在Microsoft.Office.Interop.PowerPoint.Shapes.AddPicture(字符串文件名、MSOrtistate链接文件、MSOrtistate SaveWithDocument、单左、单顶、单宽、单高)
任何帮助都将不胜感激。最终我解决了这个问题。使用下面的代码添加图片
tempSlide.Shapes.AddPicture(strImagePath, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse, Convert.ToInt32(shape.Left), Convert.ToInt32(shape.Top), Convert.ToInt32(xmlTempNode.Attributes["imgwidth"].Value), Convert.ToInt32(xmlTempNode.Attributes["imgheight"].Value));//load new image to shape
问题是,我发送msoFalse以获取LinkToFile,发送msoTrue以获取SaveWithDocument
现在,将msoTrue传递给LinkToFile,将msoFalse传递给SaveWithDocument完成了我的工作
愉快的编码..我也遇到了这个问题。我想知道你的tempSlide对象是什么?AddPicture功能似乎是根据幻灯片模板将图像添加到页面上的不同位置。我的临时幻灯片对象是
PowerPoint.Application ppApp=Globals.ThisAddIn.Application;PowerPoint.SlideRange tempSlide=ppApp.ActiveWindow.Selection.SlideRange
@user1:你能分享一下你是如何使用这个方法的吗??