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)