0

I have a problem with metafile picture insertion into a Word document from code. I need to insert picture already loaded as a System.Drawing.Image, not from path. The method:

InlineShapes.AddPicture("picture path", etc...)

won't work.

I tried to use the Paste() method, but it throws exception:

System.Runtime.InteropServices.COMException: Command error

Image image = Image.FromFile("path");
Word.Range range = selection.Range;
Clipboard.SetData(DataFormats.MetafilePicture, image);
selection.Range.Paste(); // throws exception

How can I do this?

Hopefully solution has found, thanks for @Jimi! I did a mistake:

not

Clipboard.SetData(DataFormats.MetafilePicture, image)

but

Clipboard.SetData(DataFormats.EnhancedMetafile, image)
Cindy Meister
  • 25,071
  • 21
  • 34
  • 43
Timur Fayl
  • 23
  • 4
  • 1
    `Clipboard.SetData(DataFormats.Bitmap, image);`. Btw, you have a typo here, `DataFormats.MetafilePicture`: it's `MetafilePict` or `EnhancedMetafile`. But, you'ld have to produce one. – Jimi Jun 24 '19 at 06:37
  • @Jimi, thankyou, now all works fine. – Timur Fayl Jun 24 '19 at 07:11

0 Answers0