我需要一个应用程序将文本和图像从 PowerPoint 复制到 Word。我使用这个库:Microsoft.Office.Interop.PowerPoint 和 Microsoft.Office.Interop.Word。
文本很容易传输,但是当我在 PowerPoint 中发现一个仅包含图像的形状时,它会显示此错误:“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?
欢迎任何帮助。我更喜欢一些代码示例。
Thanks.
如果你像这样重写你的代码,它会工作吗? 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);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)