我需要一个应用程序复制文本和图像从PowerPoint到Word。我使用这个库: Microsoft.Office.Interop.PowerPoint和Microsoft.Office.Interop.Word。
文本很容易传输,但是当我在PowerPoint中找到一个只包含图像的形状时,它会显示这个错误:"A generic 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?欢迎任何帮助。我更喜欢一些代码样本。
谢谢。
发布于 2010-03-01 11:40:50
如果你像这样重写你的代码,它会工作吗?GetImage将进行自动转换,以确保它是图像。如果您知道这是一个位图,您可以在代码中包含我的检查,以确保剪贴板实际上包含一个图像。
shape.Copy();
bool imgOk = Clipboard.ContainsImage();
if (imgOk)
{
Image img = Clipboard.GetImage();
MessageBox.Show(imgOk.ToString());
string filepath = @"c:\temp\img.jpg";
if (File.Exists(filepath))
{
File.Delete(filepath);
}
img.Save(filepath);
}
https://stackoverflow.com/questions/2358182
复制相似问题