【发布时间】:2012-12-10 18:38:05
【问题描述】:
我需要一个应用程序来将文本和图像从 PowerPoint 复制到 Word。我使用以下库:Microsoft.Office.Interop.PowerPoint 和 Microsoft.Office.Interop.Word。
文本很容易传输,但是当我在 PowerPoint 中找到一个只包含图像的形状时,它会显示以下错误:“A generic error occurred GDI+”,在这部分代码:
foreach (PowerPoint.Shape shape in slide.Shapes)
{
if (shape.HasTextFrame != MsoTriState.msoTrue){
shape.Copy();
Image img = (Image)Clipboard.GetData(DataFormats.Bitmap);
string filepath = Environment.SpecialFolder.Desktop + "\\img.jpg";
if (File.Exists(filepath))
{
File.Delete(filepath);
}
img.Save(filepath);
doc.Shapes.AddPicture(filepath, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
}
}
在这种情况下,如何将包含图像的形状从 PowerPoint 复制到 Word? 欢迎任何帮助。我更喜欢一些代码示例。
谢谢。
【问题讨论】:
-
是 shape.Copy() 还是 Clipboard.GetData(..) 失败了?
-
Clipboard.GetData(..) 失败
-
该代码在我的 Win7 机器(.Net4 和 Office 2010)上运行良好。它在哪个操作系统下运行以及 .Net 的哪个版本?
-
我有 .Net 3.5 和 Office 2007
标签: c# image ms-word powerpoint file-transfer