通过C#向powerpoint幻灯片添加图片throws远程过程调用失败。 (HRESULT异常:0x800706BE)

时间:2013-06-10 13:23:31

标签: 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.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();

tempSlide.Shapes.AddPicture适用于较小的图像,当分辨率较高时失败(此处失败表示无限时间内未收到响应,并且刷新页面时会抛出异常)。

异常消息:远程过程调用失败。 (HRESULT异常:0x800706BE)    在Microsoft.Office.Interop.PowerPoint.Shapes.AddPicture(String FileName,MsoTriState LinkToFile,MsoTriState SaveWithDocument,Single Left,Single Top,Single Width,Single Height)。

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:2)

最后我解决了问题。在代码下面使用addpicture

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

问题是,我正在为LinkToFile发送msoFalse,为saveWithDocument发送msoTrue。

现在,为LinkToFile传递msoTrue,为SaveWithDocument传递msoFalse完成了我的工作。

快乐的编码..

相关问题