Is there a way to paste the image (eg. from a PictureBox) directly into a Word Shape?
I'm currently using Clipboard to copy then Clipboard.SetImage(Image); But was hoping to do it directly without the Clipboard. This link How to paste image from clipboard to Word references using the Range.FormattedText, but I'm not sure how to make the Image into a FormattedText?
Here's my code using the Clipboard:
foreach (Microsoft.Office.Interop.Word.Shape s in wordApp.ActiveDocument.Shapes)
{
if (s.Title.Equals("WordImage", StringComparison.OrdinalIgnoreCase))
{
Word.Range range = s.Anchor;
Clipboard.SetImage(myPictureBox.Image);
range.Paste();
}
}
Define "directly". If you mean "is there a property of type
Shape
orInlineShape
we can set an instance of dotnet classImage
?" then the answer is NO.Both
Shape
andInlineShape
types do not expose any method to pass argument in or property to set dotnetimage
object or data ofimage
object.Instances of dotnet class
Image
should be saved into a file then added into word document withShapes.AddPicture()
method, or saved into clipboard then pasted into word document withRange.Paste()
method. There is no other way.There is a property
string Shape.RTF
, which is set-only, intuitively suggests to set rtf data of an image. But the official documentation says it is "Reserved for internal use.".Conclusion
Dotnet
Image
object cannot be inserted into Word document "directly". It canbe inserted via a file or clipboard.