C # copy of PowerPoint image form in Word

I need an application to copy text and images from PowerPoint to Word. I use these libraries: Microsoft.Office.Interop.PowerPoint and Microsoft.Office.Interop.Word.

The text is easy to carry, but when I find in PowerPoint a form containing only an image, it shows this error: " General GDI + error ", in this part of the code:

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);
   }
}

How can I copy a shape containing an image from PowerPoint to Word under these conditions? Any help is appreciated. I prefer sample code.

Thank.

+3
source share
1 answer

, ? 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);
}
0

Source: https://habr.com/ru/post/1734929/


All Articles