c# - 通过 C# 添加图片到 powerpoint 幻灯片会抛出远程过程调用失败。 (HRESULT : 0x800706BE) 的异常

标签 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(字符串文件名、MsoTriState LinkToFile、MsoTriState 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

问题是,我为 LinkToFile 发送 msoFalse,为 SaveWithDocument 发送 msoTrue。

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

快乐编码..

关于c# - 通过 C# 添加图片到 powerpoint 幻灯片会抛出远程过程调用失败。 (HRESULT : 0x800706BE) 的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17024989/

相关文章:

c# - 数组的大小是否受制于int的上限(2147483647)?

python - 使用 Python 的 win32com 控制 PowerPoint。如何以编程方式访问 "Save As"选项

vba - 创建具有脚本能力的 Powerpoint/Keynote 演示文稿?

C# - 如何以编程方式添加 Excel 工作表 - Office XP/2003

vba - 我想删除最后一个单词中的粗体/斜体/下划线格式以继续正常书写

C# WinForms : How to set Main function STAThreadAttribute

c# - 使用 LINQ 对列表条目进行分组

c# - 如何处理 Linq2Sql 列表中的空值

excel - 从第三方黑莓应用程序启动 Documents To Go 应用程序

c# - Word文档打不开